On Fri, Jul 28, 2023 at 3:05 AM Christian Mazakas via Boost
Yes. You need to resume the awaiting coroutine on the thread that called await_resume, and you'd usually do that through posting to it's executor.
Alright, I think a good next step would be formalizing this in the library then.
It's documented and formalized (https://klemens.dev/async/#associators).
We can go ahead and call this kind of abstraction Waker or something to that effect.
And then ideally this is featured in the docs.
Formalizing this Waker mechanism has the benefit that the user doesn't have to think about the lifetime of the awaiting coroutine. Because Async seems to support cancellation, the awaiting coroutine can be cancelled and destroyed before the external work `post()`s the `coroutine_handle` for execution. Naively calling `.resume()` is unsafe without some form of guarantee around lifetime.
Cancellation is a signal that you can connect to (get_cancellation_slot on the promise). It won't itself destroy the coro or anything like that. The ownership of the awaiter gets transferred to the awaitee, thus calling resume is guaranteed to work if you don't call destroy on the coroutine_handle. Likewise it's legal to destroy it, which will unwind the whole stack of coroutines.