chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

Is there a way to schedule the coroutine into the executor thread using post instead of using co_spawn? #1418

Closed zhllxt closed 5 months ago

zhllxt commented 5 months ago

If there is already a coroutine A is executing in the executor thread, at this time, if a coroutine B is generated through co_spawn, then this coroutine B will also be executed. What I want is a 'post' like effect, where coroutine B will be delivered to asio's queue. Only when coroutine A is completed can coroutine B be executed.

I know that asio::experimental::channel can meet this requirement, But I just want to know if it's possible to solve this problem without using channel and co_spawn?

zhllxt commented 5 months ago

I just want to make the following code work properly:

asio::post(ctx.get_executor(), []() -> asio::awaitable<void>
    {
        co_return;
    });