|
|
|
|
|
by _huayra_
1941 days ago
|
|
Thanks for this great article! I've been circling my way around understanding coroutines and this really put it in place. I think this co_awaiting is the most confusing part for folks: in most languages with stackful coroutines, it makes sense how one can 1. call "co_await" on a coroutine at a high-level API boundary
2. have that coroutine execute normal code all the way down to some expensive part (e.g. I/O)
3. at that particular point "deep" down in the expensive parts, that single point can just call "yield" and give control all the way back to the user thread that co_awaited at 1, usually with some special capability in the runtime. I believe the way you can do this in C++20 concepts is to co_yield a promise all the way back to the originating "co_await" site, but I may be confused about this still... It's totally clear to me why they didn't choose this for C++: keeping track of some heap-allocated stack frames could prove unwieldy. I wish more effort went into explaining and promoting coroutines. Right now the advice seems to be "be brave and DIY, or just use cppcoro until we figure this out". |
|