-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Hi, I'm looking at integrating your library into my application, since the functionality it offers would be very helpful when it comes to writing asynchronous code. The thing I'd find most useful would be to be able to call PostTaskAndReply from the existing GUI thread and have that work. Out of the box, it doesn't work, because as your documentation notes, that method has to be called from a thread with a task queue.
I can see a potential way I could work around that:
- Create a custom
MessagePump. WhenQueuePendingTaskis called, the pump would invokePostMessageto notify the main thread, via the standard Windows message loop, that a task is available. - Create a class analogous to the existing
Threadclass (something likeMainThread) that holds aSingleThreadTaskRunner. That class would run any pending tasks once notified (via thePostMessagecall). - That class would also set up the
ScopedSequenceIdSetterandSequencedTaskRunnerHandleinstances for the main thread once at startup, to ensure that there's always aSequencedTaskRunnerHandleavailable on the main thread.
I'm hoping to get your feedback on whether the last point is reasonable. My understanding is that if the main thread were solely processing tasks (and message loop items were turned into tasks), things would work, but that's a larger change that I don't really want to go through with. And it doesn't look like this library is set up to support that anyway (e.g. the Thread class only processes tasks and has no handling for something like the Windows message loop).
The solution above also requires using a few things under base::detail - for example, base::detail::SequenceIdGenerator and base::detail::ScopedSequenceIdSetter, so I'm wondering whether that could be better supported in the library.
Even without the changes above, I'd still need to be able to either customize what the thread message loop is doing (e.g. a Windows COM thread can need to pump the windows message loop) or create a custom class that does what I need. In which case, I'd still need to refer to base::detail::SequenceIdGenerator to construct the task runner.
Thanks for any help.