boost::capy::async_event
An asynchronous event for coroutines.
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
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
}
Member Functions
Name |
Description |
|
Constructors |
|
Copy assignment operator |
Clears the event. |
|
Returns true if the event is currently set. |
|
Sets the event. |
|
Returns an awaiter that waits until the event is set. |
Created with MrDocs