Clio develop
The XRP Ledger API server.
|
Manages a coroutine execution context, allowing for cooperative multitasking and cancellation. More...
#include <Coroutine.hpp>
Public Types | |
using | cancellable_yield_context_type |
Type alias for a yield_context that is bound to a cancellation slot. This allows asynchronous operations initiated with this context to be cancelled. | |
Public Member Functions | |
~Coroutine () | |
Destructor for the Coroutine. Handles cleanup, such as disconnecting from the cancellation signal. | |
Coroutine (Coroutine const &)=delete | |
Coroutine (Coroutine &&)=delete | |
Coroutine & | operator== (Coroutine &&)=delete |
Coroutine & | operator== (Coroutine const &)=delete |
template<CoroutineFunction Fn> | |
void | spawnChild (Fn fn) |
Spawns a child coroutine from this coroutine. The child coroutine shares the same cancellation signal. | |
boost::system::error_code | error () const |
Returns the error code, if any, associated with the last operation in this coroutine. | |
void | cancelAll (boost::asio::cancellation_type_t cancellationType=boost::asio::cancellation_type::terminal) |
Cancels all coroutines sharing the same root cancellation signal. | |
bool | isCancelled () const |
Checks if this coroutine has been cancelled. | |
cancellable_yield_context_type | yieldContext () const |
Returns the cancellable yield context associated with this coroutine. This context should be used for Boost.Asio asynchronous operations within the coroutine to enable cancellation. | |
boost::asio::any_io_executor | executor () const |
Returns the executor associated with this coroutine's yield context. | |
void | yield () const |
Explicitly yields execution back to the scheduler. This can be used to allow other tasks to run. | |
Static Public Member Functions | |
template<typename ExecutionContext , CoroutineFunction Fn> | |
static void | spawnNew (ExecutionContext &ioContext, Fn fn) |
Spawns a new top-level coroutine. | |
Manages a coroutine execution context, allowing for cooperative multitasking and cancellation.
The Coroutine class wraps a Boost.Asio yield_context and provides mechanisms for spawning new coroutines, child coroutines, and managing their lifecycle, including cancellation. It integrates with a signal system to propagate cancellation requests across related coroutines.
Type alias for a yield_context that is bound to a cancellation slot. This allows asynchronous operations initiated with this context to be cancelled.
void util::Coroutine::cancelAll | ( | boost::asio::cancellation_type_t | cancellationType = boost::asio::cancellation_type::terminal | ) |
Cancels all coroutines sharing the same root cancellation signal.
cancellationType | The type of cancellation to perform. Defaults to boost::asio::cancellation_type::terminal. |
|
nodiscard |
Returns the error code, if any, associated with the last operation in this coroutine.
|
nodiscard |
Returns the executor associated with this coroutine's yield context.
|
nodiscard |
Checks if this coroutine has been cancelled.
|
inline |
Spawns a child coroutine from this coroutine. The child coroutine shares the same cancellation signal.
Fn | The type of the invocable function that represents the child coroutine body. |
fn | The function to be executed as the child coroutine. It will receive a Coroutine& argument. |
|
inlinestatic |
Spawns a new top-level coroutine.
ExecutionContext | The type of the I/O execution context (e.g., boost::asio::io_context). |
Fn | The type of the invocable function that represents the coroutine body. |
ioContext | The I/O execution context on which to spawn the coroutine. |
fn | The function to be executed as the coroutine. It will receive a Coroutine& argument. |
|
nodiscard |
Returns the cancellable yield context associated with this coroutine. This context should be used for Boost.Asio asynchronous operations within the coroutine to enable cancellation.