-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_timer.cpp
64 lines (51 loc) · 1.39 KB
/
test_timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "App.h"
#include "Timer.h"
#include "ManagedTimer.h"
#include <iostream>
#include <thread>
#include <chrono>
#include <csignal>
class App;
ManagedTimer* t1;
ManagedTimer* t2;
void handleInterrupt(int signum)
{
std::cout << " Caught interrupt signal (ctr+C), stopping timers." << std::endl;
t1->stop();
t2->stop();
exit(0);
}
int main() {
App the_app{};
the_app.run();
// Timer timer{5000, [&]() { std::cout<< "done!!" << std::endl;}};
std::unique_ptr timer1 = std::make_unique<ManagedTimer>([&]() { std::cout<< "First ManagedTimer done!!" << std::endl;});
ManagedTimer timer2{[&](){ std::cout<< "second ManagedTimer done!!" << std::endl;}};
t1=timer1.get();
t2=&timer2;
signal(SIGINT, handleInterrupt);
timer1->start(5000);
timer2.start(2000);
std::cout << " waiting for the timer to expire (s): ";
int count = 0;
while(the_app.isRunning())
{
std::cout << "Main loop: " << ++count << std::endl;
std::cout.flush();
std::this_thread::sleep_for(std::chrono::seconds(1));
if (count == 3) {
timer1->stop();
}
if (count == 4) {
timer1->start(3000);
// timer2.start(1000);
}
}
std::cout << std::endl;
timer1->stop();
timer2.stop();
timer1->start(4000);
timer1->stop();
timer2.stop();
return 0;
}