#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 134 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. | |
| utils::expected< std::uint64_t, WaitAnyError > | Wait () |
| Waits either for the completion of any of the awaitables stored in the context or for the cancellation of the caller. | |
| utils::expected< std::uint64_t, WaitAnyError > | 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> | |
| utils::expected< std::uint64_t, WaitAnyError > | WaitFor (const std::chrono::duration< Rep, Period > &duration) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename Clock, typename Duration> | |
| utils::expected< std::uint64_t, WaitAnyError > | WaitUntil (const std::chrono::time_point< Clock, Duration > &until) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::size_t | GetSize () const noexcept |
| Returns the number of awaitables 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 216 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 218 of file wait_any.hpp.
|
noexcept |
|
noexcept |
| utils::expected< std::uint64_t, WaitAnyError > engine::WaitAnyContext::Wait | ( | ) |
Waits either for the completion of any of the awaitables stored in the context or for the cancellation of the caller.
The completed awaitable is dropped out of the context.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 185 of file wait_any.hpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 191 of file wait_any.hpp.
| utils::expected< std::uint64_t, WaitAnyError > 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.
The completed awaitable is dropped from the context.