|
| Task (Handle handle) |
| Construct task with coroutine handle.
|
|
| ~Task () |
| Destructor - automatically destroys coroutine handle.
|
|
| Task (const Task &)=delete |
|
Task & | operator= (const Task &)=delete |
|
| Task (Task &&other) noexcept |
| Move constructor.
|
|
Task & | operator= (Task &&other) noexcept |
| Move assignment operator.
|
|
void | start () |
| Start the coroutine execution.
|
|
bool | done () const noexcept |
| Check if the task has completed.
|
|
auto | getResult () -> T |
| Get the result value (non-blocking)
|
|
void | getResult () |
| Get the result for void tasks (non-blocking)
|
|
bool | await_ready () const noexcept |
| Check if task is ready (awaitable interface)
|
|
void | await_suspend (std::coroutine_handle<> waiter) noexcept |
| Suspend awaiting coroutine until this task completes.
|
|
auto | await_resume () -> T |
| Get result when co_await completes (non-void version)
|
|
void | await_resume () |
| Complete co_await for void tasks.
|
|
bool | isReady () const noexcept |
| Check if task is ready without blocking.
|
|
template<typename T>
class swt::Task< T >
RAII wrapper for coroutines with proper continuation chaining.
Task<T> provides a type-safe, move-only wrapper around C++20 coroutines with support for proper asynchronous execution and continuation chaining.
- Template Parameters
-
T | The return type of the coroutine |
Key features:
- RAII management: Automatic coroutine handle cleanup
- Move-only semantics: Prevents accidental copying
- Awaitable interface: Can be co_awaited by other coroutines
- Thread-safe: Safe to await from multiple threads
- Exception propagation: Proper exception handling across await boundaries
co_await std::suspend_always{};
co_return 42;
}
Task<void> example() {
int result = co_await computeAsync();
std::cout << "Result: " << result << std::endl;
}
RAII wrapper for coroutines with proper continuation chaining.
- Note
- Tasks must be started manually with start() and are lazy by default
- Warning
- Task objects must not be copied - move-only for resource safety
Definition at line 303 of file Task.h.