33template <
typename T =
void,
typename Allocator =
void>
34class [[nodiscard]]
Task :
public detail::TaskBase<T, Allocator> {
36 using Base = detail::TaskBase<T, Allocator>;
50 auto handle = std::exchange(Base::handle_,
nullptr);
51 Base::wait_inner_(handle);
52 auto exception = std::move(handle.promise()).exception();
53 if (exception) [[unlikely]] {
55 std::rethrow_exception(exception);
57 T value = std::move(handle.promise()).value();
59 return std::move(value);
63template <
typename Allocator>
65Task<void, Allocator> :
public detail::TaskBase<void, Allocator> {
67 using Base = detail::TaskBase<void, Allocator>;
79 auto handle = std::exchange(Base::handle_,
nullptr);
80 Base::wait_inner_(handle);
81 auto exception = std::move(handle.promise()).exception();
83 if (exception) [[unlikely]] {
84 std::rethrow_exception(exception);
100template <
typename T,
typename Allocator>
103 auto handle = coro.release();
104 auto &promise = handle.promise();
105 promise.mark_running();
107 runtime.schedule_internal(&promise);
119template <
typename T,
typename Allocator>
121 auto *runtime = detail::Context::current().runtime();
122 if (runtime ==
nullptr) [[unlikely]] {
123 throw std::logic_error(
"No runtime to spawn coroutine task");
125 return co_spawn(*runtime, std::move(coro));
Coroutine type used to define a coroutine function.
The event loop runtime for executing asynchronous.
Coroutine task that runs concurrently in the runtime.
T wait()
Wait synchronously for the task to complete and get the result.
Interfaces for coroutine task management.
The main namespace for the Condy library.
Task< T, Allocator > co_spawn(Runtime &runtime, Coro< T, Allocator > coro) noexcept
Spawn a coroutine as a task in the given runtime.
detail::SwitchAwaiter co_switch(Runtime &runtime) noexcept
Switch current coroutine task to the given runtime.
Runtime type for running the io_uring event loop.