userver: engine::SingleUseEvent Class Reference
Loading...
Searching...
No Matches
engine::SingleUseEvent Class Referencefinal

#include <userver/engine/single_use_event.hpp>

Detailed Description

A single-producer, single-consumer event.

Must not be awaited or signaled multiple times in the same waiting session.

The main advantage of SingleUseEvent over SingleConsumerEvent is that the waiting coroutine is allowed to immediately destroy the SingleUseEvent after waking up; it will not stop a concurrent Send from completing correctly.

Timeouts and cancellations are not supported. Only a concurrent call to Send can wake up the waiter. This is necessary for the waiter not to destroy the SingleUseEvent unexpectedly for the sender.

Example usage:

{
sender = utils::Async("sender", [&event] { event.Send(); });
event.WaitNonCancellable(); // will be woken up by 'Send()' above
// 'event' is destroyed here. Note that 'Send' might continue executing, but
// it will still complete safely.
}
See also
Synchronization Primitives

Definition at line 33 of file single_use_event.hpp.

Public Member Functions

 SingleUseEvent (const SingleUseEvent &)=delete
 
 SingleUseEvent (SingleUseEvent &&)=delete
 
SingleUseEventoperator= (const SingleUseEvent &)=delete
 
SingleUseEventoperator= (SingleUseEvent &&)=delete
 
void WaitNonCancellable () noexcept
 Waits until the event is in a signaled state.
 
void Send () noexcept
 
void Reset () noexcept
 
bool IsReady () const noexcept
 Returns true iff already signaled. Never resets the signal.
 

Constructor & Destructor Documentation

◆ SingleUseEvent()

constexpr engine::SingleUseEvent::SingleUseEvent ( )
inlineconstexprnoexcept

Definition at line 35 of file single_use_event.hpp.

Member Function Documentation

◆ Reset()

void engine::SingleUseEvent::Reset ( )
noexcept

Resets the signal flag. Can be called after WaitNonCancellable returns if necessary to reuse the SingleUseEvent for another waiting session.

◆ Send()

void engine::SingleUseEvent::Send ( )
noexcept

Sets the signal flag and wakes a coroutine that waits on it, if any. Send must not be called again without Reset.

◆ WaitNonCancellable()

void engine::SingleUseEvent::WaitNonCancellable ( )
noexcept

Waits until the event is in a signaled state.

The event then remains in a signaled state, it does not reset automatically.

The waiter coroutine can destroy the SingleUseEvent object immediately after waking up, if necessary.


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