Github   Telegram
No Matches
Public Member Functions | List of all members
engine::SingleUseEvent Class Referencefinal

A single-producer, single-consumer event. More...

#include <userver/engine/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.

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:

See also
Synchronization Primitives

Definition at line 33 of file single_use_event.hpp.

Constructor & Destructor Documentation

◆ SingleUseEvent()

constexpr engine::SingleUseEvent::SingleUseEvent ( )

Definition at line 35 of file single_use_event.hpp.

Member Function Documentation

◆ Reset()

void engine::SingleUseEvent::Reset ( )

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 ( )

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 ( )

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: