boost::capy::async_event

An asynchronous event for coroutines.

Synopsis

class async_event;

Description

This event provides a way to notify multiple coroutines that some condition has occurred. When a coroutine awaits an unset event, it suspends and is added to a wait queue. When the event is set, all waiting coroutines are resumed.

Cancellation

When a coroutine is suspended waiting for the event and its stop token is triggered, the waiter completes with error::canceled instead of waiting for set().

Cancellation only applies while the coroutine is suspended in the wait queue. If the event is already set when wait() is called, the wait completes immediately even if the stop token is already signaled.

Zero Allocation

No heap allocation occurs for wait operations.

Thread Safety

The event operations are designed for single‐threaded use on one executor. The stop callback may fire from any thread.

Example

async_event event;

task<> waiter() {
    auto [ec] = co_await event.wait();
    if(ec)
        co_return;
    // ... event was set ...
}

task<> notifier() {
    // ... do some work ...
    event.set();  // Wake all waiters
}

Types

Name

Description

wait_awaiter

Awaiter returned by wait().

Member Functions

Name

Description

async_event [constructor]

Constructors

operator= [deleted]

Copy assignment operator

clear

Clears the event.

is_set

Returns true if the event is currently set.

set

Sets the event.

wait

Returns an awaiter that waits until the event is set.

Created with MrDocs