I have read three articles of lewissbaker, and I am totally lost. And now I have also read https://blog.eiler.eu/posts/20210512/, and I am even more lost. The author gives an example https://gist.github.com/MichaEiler/99c3ed529d4fd19c4289fd04672a1a7c, and it does compile. My question is about the example.
In MichaEiler’s gist, I find the following code very strange:
inline sync_wait_task make_sync_wait_task(task& t)
{
co_await t;
}
I have several questions:
-
Why does the
make_sync_wait_task
function returnsync_wait_task
without areturn
?I guess it is because
co_await
will do some rewriting that will “return” some awaiter class. However, even if I am right here,sync_wait_task
is NOT an awaiter class, because it has noawait_
methods. -
Furthermore, why is the return type of this function
sync_wait_task
? I mean nottask
or the awaiter inthreadpool
?In fact,
sync_wait_task
has nothing to do withtask
. Thetask
class is defined without knowing about the existence ofsync_wait_task
. Then, why canco_await
ing atask
“return” async_wait_task
instance? What is the relationship here?I guess this is because
sync_wait_task
is the continuation oftask
, so somesymmetry transfer
thing happens here. Execution flows fromtask
tosync_wait_task
. If I am right, could you help me understand what exactly happens here, or relate it to the relevant sections in lewissbaker’s articles?
4