66 boost::asio::awaitable<T>
await_future(Executor &executor, std::future<T>& fut, ChronoType timeout)
68 auto timer = std::shared_ptr<boost::asio::steady_timer>{
69 new boost::asio::steady_timer{executor, timeout}
71 static boost::thread::attributes attrs;
72 attrs.set_stack_size(4096 * 8);
73 if constexpr (std::is_same_v<T, void>)
75 if (fut.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
79 boost::thread thread(attrs,
82 try { fut.wait(); timer->cancel(); }
84 catch (std::exception& e) { spdlog::error(
"Future failed with exception: {}", e.what()); }
86 catch (...) { timer->cancel(); }
89 try {
co_await timer->async_wait(boost::asio::use_awaitable);}
95 if (fut.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
99 auto result = std::make_shared<std::optional<T>>(std::nullopt);
100 boost::thread thread(attrs,
101 [timer = timer, result = result, &fut]()
103 try { fut.wait(); *result = fut.get(); timer->cancel(); }
105 catch (std::exception& e) { spdlog::error(
"Future failed with exception: {}", e.what()); }
107 catch (...) { timer->cancel(); }
110 try {
co_await timer->async_wait(boost::asio::use_awaitable); }
111 catch(std::exception &e) { }
112 if (*result == std::nullopt) {
throw future_failed{
"Future failed for unknown reason."}; }
113 co_return std::move(result->value());