push
travis-ci
18415 of 24863 relevant lines covered (74.07%)
23778.87 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,566✔ |
13 |
: m_timeoutMs(timeoutMs) |
4,566✔ |
14 |
, m_minSleepCount(minSleepCount) |
4,566✔ |
15 |
{ |
|
16 |
m_timer.start(); |
4,566✔ |
17 |
} |
4,566✔ |
18 |
|
|
19 |
bool sleep()
|
94,459,206✔ |
20 |
{ |
|
21 |
if (m_minSleepCount <= 0 && m_timer.elapsed() >= m_timeoutMs) |
94,459,206✔ |
22 |
return false; |
541✔ |
23 |
|
|
24 |
--m_minSleepCount; |
94,458,665✔ |
25 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
|
94,458,665✔ |
26 |
return true; |
94,458,665✔ |
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 |
|