The obvious way to move work off the current thread is
If I call this from and event loop context, however, then this has the dangerous side effect of executing the
work() function in a multithreaded context, and coroutines launched deep within that function can now execute simultaneously in parallel threads. Its entire call graph is now required to be thread-safe.
Since concurrency is hard, I’d rather not impose that thread-safety requirement, and I don’t trust code to be thread-safe unless that is explicitly promised.
Is there an idiomatic way to dispatch
work() off the current thread without multithreading all its internal coroutines?