14 Haziran 2021 Pazartesi

asio co_spawn

Giriş
Açıklaması şöyle
You should not, under any circumstance, get() or wait() a future to a boost::asio::awaitable from the same thread as the executor that is running the coroutine.
Örnek
Açıklaması şöyle
Thankfully, asio already provides the use_future completion token. Pass that as the third parameter to co_spawn() and it will return a std::future<> of the matching return type.
Şöyle yaparız
boost::asio::awaitable<void> foo();
boost::asio::awaitable<int> bar();

std::future<void> foo_fut = boost::asio:co_spawn(io_context, foo(),boost::asio::use_future);
std::future<int> bar_fut = boost::asio:co_spawn(io_context, bar(), boost::asio::use_future);