15 : Interval_ { interval }
17 LastInvocation_.start ();
19 Timer_.setTimerType (type);
20 Timer_.setSingleShot (
true);
21 Timer_.callOnTimeout ([
this]
23 LastInvocation_.restart ();
25 if (Queue_.size () > 1)
26 StartTimer (Interval_);
27 if (!Queue_.isEmpty ())
28 Queue_.takeFirst () ();
43 : Throttle_ { throttle }
48 : Throttle_ { other.Throttle_ }
49 , Handle_ { std::exchange (other.Handle_, {}) }
53 Throttle::Awaiter::~Awaiter ()
56 Throttle_.Queue_.removeOne (Handle_);
59 bool Throttle::Awaiter::await_ready ()
const 61 const bool allowed = std::chrono::milliseconds { Throttle_.LastInvocation_.elapsed () } >= Throttle_.Interval_ && Throttle_.Queue_.isEmpty ();
63 Throttle_.LastInvocation_.restart ();
67 void Throttle::Awaiter::await_suspend (std::coroutine_handle<> handle)
69 if (Throttle_.Queue_.isEmpty ())
70 Throttle_.StartTimer (Throttle_.Interval_ - std::chrono::milliseconds { Throttle_.LastInvocation_.elapsed () });
72 Throttle_.Queue_ << handle;
76 void Throttle::Awaiter::await_resume ()
86 void Throttle::StartTimer (std::chrono::milliseconds timeout)
88 BackoffFactor_ =
std::max (0, BackoffFactor_ - 1);
89 Timer_.start (timeout * (BackoffFactor_ + 1));
decltype(auto) Awaiter(T &&obj)
constexpr detail::AggregateType< detail::AggregateFunction::Max, Ptr > max
Throttle(std::chrono::milliseconds, Qt::TimerType=Qt::TimerType::CoarseTimer)
std::chrono::milliseconds GetInterval() const
auto Tup2 &&tup2 noexcept