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

#include <userver/engine/wait_any.hpp>

Detailed Description

Stores a set of awaitables and allows waiting for completion of any of the stored awaitables.

Works with different types of awaitables:

No methods (except .dtor) should be called on a moved-out instance.

Definition at line 122 of file wait_any.hpp.

Public Member Functions

 WaitAnyContext (WaitAnyContext &&) noexcept
 
WaitAnyContextoperator= (WaitAnyContext &&other) noexcept
 
 WaitAnyContext (const WaitAnyContext &)=delete
 
WaitAnyContextoperator= (const WaitAnyContext &)=delete
 
template<typename... Awaitables>
void Append (Awaitables &... awaitables)
 Append the given awaitables and sequences of awaitables to the context.
 
std::optional< std::uint64_t > Wait ()
 Waits either for the completion of any of the awaitables stored in the context or for the cancellation of the caller.
 
std::optional< std::uint64_t > WaitUntil (Deadline deadline)
 
template<typename Rep, typename Period>
std::optional< std::uint64_t > WaitFor (const std::chrono::duration< Rep, Period > &duration)
 
template<typename Clock, typename Duration>
std::optional< std::uint64_t > WaitUntil (const std::chrono::time_point< Clock, Duration > &until)
 
std::size_t GetSize () const noexcept
 Returns the number of awaitables actually stored in the context.
 
std::uint64_t GetNextIndex () const noexcept
 Returns the next awaitable index.
 

Member Function Documentation

◆ Append()

template<typename... Awaitables>
void engine::WaitAnyContext::Append ( Awaitables &... awaitables)

Append the given awaitables and sequences of awaitables to the context.

Each passed awaitable could be either a single awaitable or a container of awaitables. In the latter case all awaitables from the container are appended to the context. The appended awaitables will have indexes [GetNextIndex() before the call, GetNextIndex() after the call - 1].

Definition at line 203 of file wait_any.hpp.

◆ GetNextIndex()

std::uint64_t engine::WaitAnyContext::GetNextIndex ( ) const
noexcept

Returns the next awaitable index.

It could be used to calculate indexes of awaitables appended via Append call.

◆ GetSize()

std::size_t engine::WaitAnyContext::GetSize ( ) const
noexcept

Returns the number of awaitables actually stored in the context.

It consists of actively awaited and pending subscription awaitables. Already notified awaitables are dropped out.

◆ Wait()

std::optional< std::uint64_t > engine::WaitAnyContext::Wait ( )

Waits either for the completion of any of the awaitables stored in the context or for the cancellation of the caller.

Returns
the index of the completed awaitable, or std::nullopt if there are no completed awaitables (possible if current task was cancelled).

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ WaitFor()

template<typename Rep, typename Period>
std::optional< std::uint64_t > engine::WaitAnyContext::WaitFor ( const std::chrono::duration< Rep, Period > & duration)
inline

Definition at line 151 of file wait_any.hpp.

◆ WaitUntil()

template<typename Clock, typename Duration>
std::optional< std::uint64_t > engine::WaitAnyContext::WaitUntil ( const std::chrono::time_point< Clock, Duration > & until)
inline

Definition at line 157 of file wait_any.hpp.


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