forked from berndporr/cppTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_runnable.cpp
More file actions
43 lines (33 loc) · 884 Bytes
/
demo_runnable.cpp
File metadata and controls
43 lines (33 loc) · 884 Bytes
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
#include <stdio.h>
#include "CppTimerCallback.h"
#include <unistd.h>
#include <thread>
class Callback1 : public CppTimerCallback::Runnable {
void run() {
fprintf(stdout,"Bah! ");
fflush(stdout);
}
};
class Callback2 : public CppTimerCallback::Runnable {
void run() {
fprintf(stdout,"Buh! \n");
fflush(stdout);
}
};
int main( int argc, const char* argv[] ) {
CppTimerCallback demoTimer1;
Callback1 callback1;
demoTimer1.registerEventRunnable(callback1);
demoTimer1.start(2500000);
CppTimerCallback demoTimer2;
Callback2 callback2;
demoTimer2.registerEventRunnable(callback2);
demoTimer2.start(10000000);
// do nothing and keep sleeping for 2 secs
std::this_thread::sleep_for(std::chrono::seconds(2));
demoTimer1.unregisterEventRunnable();
demoTimer1.stop();
demoTimer2.unregisterEventRunnable();
demoTimer2.stop();
printf("\n");
}