-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathusage.cpp
More file actions
37 lines (35 loc) · 1014 Bytes
/
usage.cpp
File metadata and controls
37 lines (35 loc) · 1014 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
#include "eventemitter.h"
#include <iostream>
int main() {
EventEmitter<std::string> ee;
ee.on("event", []() {
std::cout << 1;
});
auto cancel2 = ee.on("event", []() {
std::cout << 2;
});
ee.on("event", []() {
std::cout << 3;
});
std::cout << "Number of existing event names:" <<
ee.names().size() << std::endl;
std::cout <<
"Number of listeners listening to the event using EventEmitter::count:" <<
ee.count("event") << std::endl;
std::cout <<
"Number of listeners listening to the event using EventEmitter::listeners:" <<
ee.listeners("event").size() << std::endl;
ee.emit("event");
std::cout << std::endl;
cancel2();
ee.emit("event");
std::cout << std::endl;
ee.clear("event");
ee.emit("event");
EventEmitter<std::string, std::string> eeWithArgs;
eeWithArgs.on("event", [](std::string data) {
std::cout << data;
});
eeWithArgs.emit("event", "hello ");
eeWithArgs.emit("event", "there");
}