-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pigeon] Adds support of TaskQueue for Swift #8501
base: main
Are you sure you want to change the base?
Conversation
@@ -851,6 +854,7 @@ if (wrapped == nil) { | |||
}) { | |||
return 'try instanceManager.removeAllObjects()'; | |||
}, | |||
taskQueueType: TaskQueueType.serial, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is serial task queue the only supported type? do we support concurrent queue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we support concurrent queue?
We have never had a use case in our own plugins for concurrent queues, AFAIK nobody else has ever requested it, and I would not expect concurrent task queues to be a common use case in platform channels, so currently we have had no reason to implement it.
indent.writeln( | ||
'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger, codec: codec)'); | ||
String? taskQueue; | ||
if (taskQueueType != TaskQueueType.serial) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im confused here - does TaskQueueType.serial
mean it's not background queue? If it means it's a main queue, maybe we should rename to serialMainQueue
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc states:
/// Handlers are invoked serially on the default thread. This is the value if
/// unspecified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im confused here - does
TaskQueueType.serial
mean it's not background queue?
No, it means that all calls on that API object using the serial task queue will be executed in order, each one completing before the next starts.
As compared with, e.g., a default NSOperationQueue
, which will dispatch jobs into a thread pool, and might run everything in parallel on N different threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handlers are invoked serially on the default thread.
Is the "default thread" referring to main thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's an arbitrary background thread. That's why the API called by the generated code is makeBackgroundTaskQueue
.
Calling things serially on the main thread is what platform channels do by default, and what they always did before the creation of the task queue API. The whole point of adding task queues to the channel APIs in the engine was to move them off of the main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please forgive my numerous questions, I think I may be missing something.
What you just described sounds very like the .serialBackgroundThread
case, rather than the .serial
case. Also, the code here is:
if NOT serial { // the only other case is serialBackgroundThread
use makeBackgroundTaskQueue API
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you just described sounds very like the
.serialBackgroundThread
case, rather than the.serial
case.
Sorry, I forgot that Pigeon for some reason has a task queue enum value that actually means "don't use task queues". I have no idea why it was written that way; it's incredibly confusing.
So yes, it's the main thread and everything I said was wrong.
maybe we should rename to
serialMainQueue
instead
We should probably just remove it, or if we keep it call it the even simpler none
, but either way that's out of scope here.
let result = try api.echoAllTypesTaskQueueBackground(everythingArg) | ||
reply(wrapResult(result)) | ||
} catch { | ||
reply(wrapError(error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC reply
should still be called on main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be sufficient to add?
DispatchQueue.main.async {
reply(wrapResult(result))
}
like it is mentioned in docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC
reply
should still be called on main thread.
Please see the second bullet point here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC
reply
should still be called on main thread.Please see the second bullet point here.
Sorry i misread your message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at it again, I must have misunderstood the 3rd bullet point as the reply
call. Sorry for the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have misunderstood the 3rd bullet point as the
reply
call
Does it have any implications for the discussion in this PR?
Apologies if I’m missing something.
corrects linux methods' names, windows response, swift redeclaration taskQueue variable
TaskQueue
for Swiftcloses 111512
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].CHANGELOG.md
to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].///
).