Код: Выделить всё
#define BOOST_THREAD_PROVIDES_FUTURE 1
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION 1
#define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY 1
#include
#include
#include
#include
#include
using namespace boost::asio::experimental::awaitable_operators;
namespace asio = boost::asio;
auto running_task() -> boost::asio::awaitable
{
std::println("starting the coroutine ....");
auto timer = asio::system_timer{ co_await asio::this_coro::executor };
timer.expires_after(std::chrono::seconds(10));
co_await timer.async_wait(asio::use_awaitable);
std::println("finishing the coroutine ....");
}
auto main() -> int
{
auto io_context = boost::asio::thread_pool{ 4 };
auto fut = asio::co_spawn(io_context, running_task() , asio::use_future);
io_context.join();
return 0;
}
Я пытался использовать Boost :: rexectors :: basic_thread_pool , чтобы иметь Boost :: Future
Подробнее здесь: https://stackoverflow.com/questions/797 ... readfuture
Мобильная версия