A function becomes a coroutine the moment you suspend from within its body by invoking co_await or co_yield and co_return.
If you call a coroutine c (remember, coroutines are just functions) from a function f, the function f is not a coroutine unless you co_await the result of c.
In other words, calling a coroutine isn’t sufficient to make the caller a coroutine.
asio::awaitable<void> intermediate(){ SPDLOG_INFO("Before lambda"); auto res = []() -> asio::awaitable<int> { // lambda is not a coroutine int i = 42; SPDLOG_INFO("Before make_awaitable"); auto r = make_awaitable(i); SPDLOG_INFO("After make_awaitable"); return r; }(); SPDLOG_INFO("After lambda"); auto n = co_await std::move(res); }
asio::awaitable<void> launcher(){ SPDLOG_INFO("Before intermediate"); auto r = intermediate(); SPDLOG_INFO("After intermediate"); co_awaitstd::move(r); co_return; }
asio::awaitable<void> intermediate() { SPDLOG_INFO("Before lambda"); auto res = []() -> asio::awaitable<int> { // lambda is not a coroutine int i = 42; SPDLOG_INFO("Before make_awaitable"); auto r = make_awaitable(i); SPDLOG_INFO("After make_awaitable"); - return r; + co_return 42; }(); SPDLOG_INFO("After lambda"); auto n = co_await std::move(res); }