Function async_run

Synopsis

#include <lib/inc/drogon/utils/coroutine.h>

template <typename Coro>
void async_run(Coro &&coro)

Description

Runs a coroutine from a regular function.

Parameters

coro - A coroutine that is awaitable

Mentioned in

Source

Lines 713-727 in lib/inc/drogon/utils/coroutine.h.

template <typename Coro>
void async_run(Coro &&coro)
{
    using CoroValueType = std::decay_t<Coro>;
    auto functor = [](CoroValueType coro) -> AsyncTask {
        auto frame = coro();

        using FrameType = std::decay_t<decltype(frame)>;
        static_assert(is_awaitable_v<FrameType>);

        co_await frame;
        co_return;
    };
    functor(std::forward<Coro>(coro));
}





Add Discussion as Guest

Log in