-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdemo_stdfunccallback.cpp
More file actions
46 lines (35 loc) · 1017 Bytes
/
demo_stdfunccallback.cpp
File metadata and controls
46 lines (35 loc) · 1017 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
44
45
46
#include <stdio.h>
#include "CppTimerStdFuncCallback.h"
#include <unistd.h>
#include <thread>
// Demo which shows how to register a callback via a lambda function.
// The method run() in the receiving classes below is called from the class CppTimerCallback.
class ReceiverClass1 {
public:
void run() {
fprintf(stdout,"Bah! ");
fflush(stdout);
}
};
class ReceiverClass2 {
public:
void run() {
fprintf(stdout,"BUH! \n");
fflush(stdout);
}
};
int main( int, const char**) {
CppTimerCallback demoTimer1;
ReceiverClass1 receiverClass1;
demoTimer1.registerEventCallback([&receiverClass1](){receiverClass1.run();});
demoTimer1.startns(77000000);
CppTimerCallback demoTimer2;
ReceiverClass2 receiverClass2;
demoTimer2.registerEventCallback([&receiverClass2](){receiverClass2.run();});
demoTimer2.startns(250000000);
// do nothing and keep sleeping for 2 secs
std::this_thread::sleep_for(std::chrono::seconds(2));
demoTimer1.stop();
demoTimer2.stop();
printf("\n");
}