LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
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
18
namespace
LC::Util
19
{
20
class
UTIL_THREADS_API
Throttle
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
30
struct
Awaiter
31
{
32
Throttle
& Throttle_;
33
std::coroutine_handle<> Handle_ {};
34
35
explicit
Awaiter (
Throttle
& throttle);
36
Awaiter (Awaiter&& other)
noexcept
;
37
38
Awaiter (
const
Awaiter&) =
delete
;
39
Awaiter& operator= (
const
Awaiter&) =
delete
;
40
Awaiter& operator= (Awaiter&&) =
delete
;
41
42
~Awaiter ();
43
44
bool
await_ready ()
const
;
45
void
await_suspend (std::coroutine_handle<>);
46
void
await_resume ();
47
};
48
public
:
49
explicit
Throttle
(std::chrono::milliseconds, Qt::TimerType = Qt::TimerType::CoarseTimer);
50
51
std::chrono::milliseconds
GetInterval
()
const
;
52
53
void
Backoff
();
54
55
Awaiter
operator
co_await
();
56
private
:
57
void
StartTimer (std::chrono::milliseconds);
58
};
59
60
using
Throttle_ptr
= std::shared_ptr<Throttle>;
61
}
LC::Util::Throttle::Backoff
void Backoff()
Definition
throttle.cpp:37
LC::Util::Throttle::GetInterval
std::chrono::milliseconds GetInterval() const
Definition
throttle.cpp:32
LC::Util::Throttle::Throttle
Throttle(std::chrono::milliseconds, Qt::TimerType=Qt::TimerType::CoarseTimer)
Definition
throttle.cpp:14
LC::Util
Definition
icoreproxy.h:34
LC::Util::Throttle_ptr
std::shared_ptr< Throttle > Throttle_ptr
Definition
throttle.h:60
threadsconfig.h
UTIL_THREADS_API
#define UTIL_THREADS_API
Definition
threadsconfig.h:16
src
util
threads
coro
throttle.h
Generated by
1.17.0