wwa-coro
0.0.1
Yet Another C++20 Coroutine Library
src
eager_task.h
Go to the documentation of this file.
1
#ifndef CF9BADEE_8060_4165_91B2_54C840903F88
2
#define CF9BADEE_8060_4165_91B2_54C840903F88
3
14
15
#include <coroutine>
16
#include <exception>
17
#include <functional>
18
19
namespace
wwa::coro
{
20
21
// NOLINTBEGIN(readability-convert-member-functions-to-static)
31
class
eager_task
{
32
public
:
41
struct
promise_type
{
43
52
[[nodiscard]]
constexpr
auto
get_return_object()
const
{
return
eager_task
{}; }
53
63
[[noreturn]]
void
unhandled_exception()
const
noexcept
{ std::terminate(); }
64
73
constexpr
void
return_void()
const
noexcept
{}
74
87
[[nodiscard]]
constexpr
auto
initial_suspend()
const
noexcept
{
return
std::suspend_never{}; }
88
101
[[nodiscard]]
constexpr
auto
final_suspend()
const
noexcept
{
return
std::suspend_never{}; }
102
104
};
105
};
106
// NOLINTEND(readability-convert-member-functions-to-static)
107
112
127
template
<
typename
Awaitable,
typename
... Args>
128
// NOLINTNEXTLINE(cppcoreguidelines-avoid-reference-coroutine-parameters)
129
eager_task
run_awaitable
(Awaitable&& f, Args&&... args)
130
{
131
co_await
std::invoke(std::forward<Awaitable>(f), std::forward<Args>(args)...);
132
}
133
138
139
}
// namespace wwa::coro
140
141
#endif
/* CF9BADEE_8060_4165_91B2_54C840903F88 */
wwa::coro::eager_task
Eager coroutine.
Definition
eager_task.h:31
wwa::coro
Library namespace.
Definition
async_generator.h:30
wwa::coro::run_awaitable
eager_task run_awaitable(Awaitable &&f, Args &&... args)
Turns any awaitable into an eager fire-and-forget coroutine.
Definition
eager_task.h:129
wwa::coro::eager_task::promise_type
The promise type for the eager_task coroutine.
Definition
eager_task.h:41
Generated by
1.13.2