Condy v1.1.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
condy::Task< T, Allocator > Class Template Reference

Coroutine task that runs concurrently in the runtime. More...

#include <task.hpp>

Public Member Functions

wait ()
 Wait synchronously for the task to complete and get the result.
void detach () noexcept
 Detach the task to run independently.
auto operator co_await () noexcept
 Await the task asynchronously.

Detailed Description

template<typename T = void, typename Allocator = void>
class condy::Task< T, Allocator >

Coroutine task that runs concurrently in the runtime.

Template Parameters
TReturn type of the coroutine.
AllocatorAllocator type used for memory management, default is void, which means use the default allocator.

Task is a handle to a coroutine task that can be awaited or detached. The coroutine will be scheduled and executed in the associated runtime. User can await the task to get the result of the coroutine, or detach the task to let it run independently.

Warning
Destroying a Task without awaiting or detaching it will cause a panic.
Unhandled exceptions in a detached task will also cause a panic.

Member Function Documentation

◆ detach()

template<typename T = void, typename Allocator = void>
void condy::TaskBase< T, Allocator >::detach ( )
inlinenoexceptinherited

Detach the task to run independently.

This function detaches the task, allowing it to run independently in the associated runtime. The caller will not be able to await the task or retrieve its result after detachment.

Warning
Unhandled exceptions in a detached task will cause a panic.

◆ operator co_await()

template<typename T, typename Allocator>
auto condy::TaskBase< T, Allocator >::operator co_await ( )
inlinenoexceptinherited

Await the task asynchronously.

Returns
T The result of the coroutine.
Exceptions
Anyexception thrown inside the coroutine.

This function allows the caller to await the completion of the coroutine associated with the task. It suspends the caller coroutine until the task completes, and then retrieves the result of the coroutine. If the coroutine throws an exception, it will be rethrown here.

◆ wait()

template<typename T = void, typename Allocator = void>
T condy::Task< T, Allocator >::wait ( )
inline

Wait synchronously for the task to complete and get the result.

Returns
T The result of the coroutine.
Exceptions
Anyexception thrown inside the coroutine.

This function blocks the current thread until the coroutine associated with the task completes. It then retrieves the result of the coroutine. If the coroutine throws an exception, it will be rethrown here.


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