#include <userver/engine/wait_any.hpp>
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 124 of file wait_any.hpp.
Public Member Functions | |
| WaitAnyContext (WaitAnyContext &&) noexcept | |
| WaitAnyContext & | operator= (WaitAnyContext &&other) noexcept |
| WaitAnyContext (const WaitAnyContext &)=delete | |
| WaitAnyContext & | operator= (const WaitAnyContext &)=delete |
| void | Append (engine::Awaitable auto &awaitable) |
| Appends a single awaitable to the context. | |
| void | Append (std::uint64_t id, engine::Awaitable auto &awaitable) |
| Appends the given awaitable to the context with an explicit id. | |
| 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) |
| Waits for the completion of any of the awaitables stored in the context or cancellation of the caller or deadline expiration. | |
| template<typename Rep, typename Period> | |
| std::optional< std::uint64_t > | WaitFor (const std::chrono::duration< Rep, Period > &duration) |
| Waits for the completion of any of the awaitables stored in the context or cancellation of the caller or expiration of the given 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 | GetNextId () const noexcept |
| Returns the next id that will be assigned by the next Append call. | |
| void engine::WaitAnyContext::Append | ( | engine::Awaitable auto & | awaitable | ) |
Appends a single awaitable to the context.
The appended awaitable will be assigned the next id from the auto-incrementing counter; see also GetNextId.
Definition at line 205 of file wait_any.hpp.
| void engine::WaitAnyContext::Append | ( | std::uint64_t | id, |
| engine::Awaitable auto & | awaitable ) |
Appends the given awaitable to the context with an explicit id.
The id is an arbitrary number that will be returned by Wait. It does not have to be sequential or starting from 0. Duplicate ids are allowed.
GetNextId will be unaffected by this call. When mixing the id-less Append and this overload, the id-less Append maintains a sequence only within its own calls.
Works well together with utils::SlotMap to process and erase tasks in completion order:
| id | the id that will be returned by Wait. |
| awaitable | the awaitable to append. |
Definition at line 207 of file wait_any.hpp.
|
noexcept |
|
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.
| 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.
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.
|
inline |
Waits for the completion of any of the awaitables stored in the context or cancellation of the caller or expiration of the given duration.
std::nullopt if there are no completed awaitables (possible if current task was cancelled or the given duration has passed). Definition at line 174 of file wait_any.hpp.
|
inline |
Definition at line 180 of file wait_any.hpp.
| std::optional< std::uint64_t > engine::WaitAnyContext::WaitUntil | ( | Deadline | deadline | ) |
Waits for the completion of any of the awaitables stored in the context or cancellation of the caller or deadline expiration.
std::nullopt if there are no completed awaitables (possible if current task was cancelled or the deadline was reached).