Function co_future
Synopsis
#include <lib/inc/drogon/utils/coroutine.h>
template <typename Await>
auto co_future(Await &&await) noexcept -> std::future< await_result_t< Await >>
Description
No description yet.
Source
Lines 628-652 in lib/inc/drogon/utils/coroutine.h.
template <typename Await>
inline auto co_future(Await &&await) noexcept
-> std::future<await_result_t<Await>>
{
using Result = await_result_t<Await>;
std::promise<Result> prom;
auto fut = prom.get_future();
[](std::promise<Result> prom, Await await) -> AsyncTask {
try
{
if constexpr (std::is_void_v<Result>)
{
co_await std::move(await);
prom.set_value();
}
else
prom.set_value(co_await std::move(await));
}
catch (...)
{
prom.set_exception(std::current_exception());
}
}(std::move(prom), std::move(await));
return fut;
}