boost::capy::async_event
Queues coroutines in wait() and resumes all of them when set() is called.
Synopsis
Declared in <boost/capy/ex/async_event.hpp>
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.
Thread Safety
Distinct objects: Safe. Shared objects: Unsafe.
The event operations are designed for single‐threaded use on one executor. The stop callback may fire from any thread.
This type is non‐copyable and non‐movable because suspended waiters hold intrusive pointers into the event's internal list.
Example
capy::async_event event;
capy::task<> waiter() {
auto [ec] = co_await event.wait();
if(ec)
co_return;
// ... event was set ...
}
capy::task<> notifier() {
// ... do some work ...
event.set(); // Wake all waiters
co_return;
}
Types
Name |
Description |
Suspends the caller until |
Member Functions
Name |
Description |
|
Constructors |
|
Destroy the event, canceling every coroutine still waiting. |
Assignment operators |
|
Clears the event. |
|
Returns true if the event is currently set. |
|
Resumes every waiting coroutine and marks the event set for later |
|
Returns an awaiter that waits until the event is set. |
Created with MrDocs