My application use boost.asio to run network related tasks that yield (coroutines).
On some occasions when my task is spawned from another spawned task, it's being called directly from the current task's callstack.
I would expect that it'll be queued and may run after the current task get suspended (if no other tasks are pending on the same io_context)
looking at the spawn code, it reaches boost::asio::dispatch which trigger async operation
return async_initiate<NullaryToken, void()>(
detail::initiate_dispatch(), token);
So it seems odd that my task has been called directly and not from some dispatcher, is it possible ?
Thanks
asio::dispatchis documented to dispatch on an executor.The
Executorconcept documents the behaviour fordispatchas:(emphasis mine).
Contrast this with
postordefer:Simply put:
dispatchMAY execute the handler immediately but only if the currently executing executor implements this optimization and is compatible with the associated executor.See also for background/examples:
What is the difference between post and dispatch from boost::asio when overloads with executor parameter are used?
`strand::running_in_this_thread()` false positive