push
travis-ci
18382 of 24735 relevant lines covered (74.32%)
24841.43 hits per line
1 |
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2 |
|
|
3 |
#ifndef SLEEPTIMER_H
|
|
4 |
#define SLEEPTIMER_H
|
|
5 |
|
|
6 |
#include <QCoreApplication> |
|
7 |
#include <QElapsedTimer> |
|
8 |
|
|
9 |
class SleepTimer final |
|
10 |
{ |
|
11 |
public:
|
|
12 |
explicit SleepTimer(int timeoutMs, int minSleepCount = 2) |
4,648✔ |
13 |
: m_timeoutMs(timeoutMs) |
4,648✔ |
14 |
, m_minSleepCount(minSleepCount) |
4,648✔ |
15 |
{ |
|
16 |
m_timer.start(); |
4,648✔ |
17 |
} |
4,648✔ |
18 |
|
|
19 |
bool sleep()
|
96,826,621✔ |
20 |
{ |
|
21 |
if (m_minSleepCount <= 0 && m_timer.elapsed() >= m_timeoutMs) |
96,826,621✔ |
22 |
return false; |
555✔ |
23 |
|
|
24 |
--m_minSleepCount; |
96,826,066✔ |
25 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
|
96,826,066✔ |
26 |
return true; |
96,826,066✔ |
27 |
} |
|
28 |
|
|
29 |
private:
|
|
30 |
QElapsedTimer m_timer; |
|
31 |
int m_timeoutMs;
|
|
32 |
int m_minSleepCount = 2; |
|
33 |
}; |
|
34 |
|
|
35 |
inline void waitFor(int ms) |
|
36 |
{ |
|
37 |
SleepTimer t(ms); |
× |
38 |
while (t.sleep()) {}
|
× |
39 |
} |
|
40 |
|
|
41 |
#endif // SLEEPTIMER_H |
|
42 |
|