LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
throttle.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <coroutine>
12#include <chrono>
13#include <QElapsedTimer>
14#include <QTimer>
15#include <QVector>
16#include "../threadsconfig.h"
17
18namespace LC::Util
19{
21 {
22 QTimer Timer_;
23 QElapsedTimer LastInvocation_;
24 std::chrono::milliseconds Interval_;
25
26 QVector<std::coroutine_handle<>> Queue_;
27
28 int BackoffFactor_ = 0;
29 public:
30 explicit Throttle (std::chrono::milliseconds, Qt::TimerType = Qt::TimerType::CoarseTimer);
31
32 std::chrono::milliseconds GetInterval () const;
33
34 void Backoff ();
35
36 bool await_ready ();
37 void await_suspend (std::coroutine_handle<>);
38 void await_resume () const;
39 private:
40 void StartTimer (std::chrono::milliseconds);
41 };
42
43 using Throttle_ptr = std::shared_ptr<Throttle>;
44}
std::chrono::milliseconds GetInterval() const
Definition throttle.cpp:31
void await_resume() const
Definition throttle.cpp:57
void await_suspend(std::coroutine_handle<>)
Definition throttle.cpp:49
Throttle(std::chrono::milliseconds, Qt::TimerType=Qt::TimerType::CoarseTimer)
Definition throttle.cpp:14
std::shared_ptr< Throttle > Throttle_ptr
Definition throttle.h:43
#define UTIL_THREADS_API