9#include <userver/engine/deadline.hpp>
10#include <userver/engine/impl/wait_list_fwd.hpp>
12USERVER_NAMESPACE_BEGIN
19class SingleConsumerEvent
final {
21 struct NoAutoReset
final {};
29 SingleConsumerEvent(
const SingleConsumerEvent&) =
delete;
30 SingleConsumerEvent(SingleConsumerEvent&&) =
delete;
31 SingleConsumerEvent& operator=(
const SingleConsumerEvent&) =
delete;
32 SingleConsumerEvent& operator=(SingleConsumerEvent&&) =
delete;
33 ~SingleConsumerEvent();
50 template <
typename Clock,
typename Duration>
51 [[nodiscard]]
bool WaitForEventFor(std::chrono::duration<Clock, Duration>);
54 template <
typename Clock,
typename Duration>
55 [[nodiscard]]
bool WaitForEventUntil(std::chrono::time_point<Clock, Duration>);
58 [[nodiscard]]
bool WaitForEventUntil(Deadline);
81 template <
typename Predicate>
82 [[nodiscard]]
bool WaitUntil(Deadline, Predicate stop_waiting);
99 [[nodiscard]]
bool IsReady()
const noexcept;
102 class EventWaitStrategy;
104 bool GetIsSignaled()
noexcept;
106 void CheckIsAutoResetForWaitPredicate();
108 impl::FastPimplWaitListLight waiters_;
109 const bool is_auto_reset_{
true};
112template <
typename Clock,
typename Duration>
113bool SingleConsumerEvent::WaitForEventFor(std::chrono::duration<Clock, Duration> duration) {
114 return WaitForEventUntil(Deadline::FromDuration(duration));
117template <
typename Clock,
typename Duration>
118bool SingleConsumerEvent::WaitForEventUntil(std::chrono::time_point<Clock, Duration> time_point) {
119 return WaitForEventUntil(Deadline::FromTimePoint(time_point));
122template <
typename Predicate>
123bool SingleConsumerEvent::WaitUntil(Deadline deadline, Predicate stop_waiting) {
124 CheckIsAutoResetForWaitPredicate();
129 while (!stop_waiting()) {
137 if (!WaitForEventUntil(deadline)) {