travis-ci
2 of 2 new or added lines in 1 file covered. (100.0%)
18366 of 24734 relevant lines covered (74.25%)
23030.62 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,649✔ |
13 |
: m_timeoutMs(timeoutMs) |
4,649✔ |
14 |
, m_minSleepCount(minSleepCount) |
4,649✔ |
15 |
{ |
|
16 |
m_timer.start(); |
4,649✔ |
17 |
} |
4,649✔ |
18 |
|
|
19 |
bool sleep()
|
88,940,557✔ |
20 |
{ |
|
21 |
if (m_minSleepCount <= 0 && m_timer.elapsed() >= m_timeoutMs) |
88,940,557✔ |
22 |
return false; |
554✔ |
23 |
|
|
24 |
--m_minSleepCount; |
88,940,003✔ |
25 |
QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
|
88,940,003✔ |
26 |
return true; |
88,940,003✔ |
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 |
|