Lightweight 0.20260617.0
Loading...
Searching...
No Matches
Lightweight::Async::Task< T > Class Template Reference

#include <Task.hpp>

Public Types

using promise_type = detail::TaskPromise< T >
 The coroutine promise type required by the C++ coroutine machinery.
 
using Handle = std::coroutine_handle< promise_type >
 The typed coroutine handle owned by this Task.
 

Public Member Functions

 Task () noexcept=default
 Constructs an empty Task that owns no coroutine.
 
 Task (Handle handle) noexcept
 
 Task (Task &&other) noexcept
 
Taskoperator= (Task &&other) noexcept
 
 Task (Task const &)=delete
 
Taskoperator= (Task const &)=delete
 
bool IsValid () const noexcept
 
bool IsReady () const noexcept
 
Handle GetHandle () const noexcept
 
auto operator co_await () &&noexcept
 

Detailed Description

template<typename T>
class Lightweight::Async::Task< T >

A lazy, move-only C++23 coroutine task.

A Task<T> represents an asynchronous computation that yields a value of type T (or nothing for Task<void>). It is lazy — the coroutine body does not start executing until the Task is co_await-ed by another coroutine or driven to completion by SyncWait / SyncWaitPumping. Awaiting uses symmetric transfer, so chains of awaits do not grow the stack. Exceptions thrown inside the body are captured and rethrown at the awaiting site (parity with the throwing synchronous API).

Template Parameters
TThe value type produced by the task (defaults to void).

Definition at line 205 of file Task.hpp.

Member Typedef Documentation

◆ promise_type

template<typename T >
using Lightweight::Async::Task< T >::promise_type = detail::TaskPromise<T>

The coroutine promise type required by the C++ coroutine machinery.

Definition at line 209 of file Task.hpp.

◆ Handle

template<typename T >
using Lightweight::Async::Task< T >::Handle = std::coroutine_handle<promise_type>

The typed coroutine handle owned by this Task.

Definition at line 212 of file Task.hpp.

Constructor & Destructor Documentation

◆ Task() [1/2]

template<typename T >
Lightweight::Async::Task< T >::Task ( Handle  handle)
inlineexplicitnoexcept

Adopts ownership of the coroutine identified by handle (used by the promise).

Parameters
handleThe coroutine handle to take ownership of.

Definition at line 219 of file Task.hpp.

◆ Task() [2/2]

template<typename T >
Lightweight::Async::Task< T >::Task ( Task< T > &&  other)
inlinenoexcept

Move-constructs from other, leaving it empty.

Parameters
otherThe Task to move from.

Definition at line 226 of file Task.hpp.

◆ ~Task()

template<typename T >
Lightweight::Async::Task< T >::~Task ( )
inline

Definition at line 248 of file Task.hpp.

Member Function Documentation

◆ operator=()

template<typename T >
Task & Lightweight::Async::Task< T >::operator= ( Task< T > &&  other)
inlinenoexcept

Move-assigns from other, destroying any currently-owned coroutine first.

Parameters
otherThe Task to move from.
Returns
A reference to this Task.

Definition at line 234 of file Task.hpp.

◆ IsValid()

template<typename T >
bool Lightweight::Async::Task< T >::IsValid ( ) const
inlinenoexcept
Returns
true if this Task owns a coroutine frame.

Definition at line 255 of file Task.hpp.

◆ IsReady()

template<typename T >
bool Lightweight::Async::Task< T >::IsReady ( ) const
inlinenoexcept
Returns
true if the Task is empty or has run to completion.

Definition at line 261 of file Task.hpp.

◆ GetHandle()

template<typename T >
Handle Lightweight::Async::Task< T >::GetHandle ( ) const
inlinenoexcept
Returns
the underlying coroutine handle (used by SyncWait and executors).

Definition at line 267 of file Task.hpp.

◆ operator co_await()

template<typename T >
auto Lightweight::Async::Task< T >::operator co_await ( ) &&
inlinenoexcept

Awaits this Task: suspends the awaiting coroutine, runs this Task, and yields its result (or rethrows its exception) once it completes.

Returns
An awaiter for this Task.

Definition at line 275 of file Task.hpp.


The documentation for this class was generated from the following files: