-
Notifications
You must be signed in to change notification settings - Fork 8
/
EventLoop.h
48 lines (31 loc) · 806 Bytes
/
EventLoop.h
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
#ifndef EVENTLOOP
#define EVENTLOOP
#include <vector>
#include <functional>
class Vow {
private:
std::vector<std::function<void()>> callbacks;
public:
bool resolved = false;
void then(std::function<void()> cb);
void resolve();
};
class EventLoop {
private:
bool running = false;
std::vector<std::function<void()>> callbacks;
std::vector<int> callbackTimes;
public:
EventLoop();
int time = 0;
int ticks = 0;
Vow *setTimeout(int delay, std::function<void()> cb);
Vow *setInterval(int delay, std::function<void()> cb);
Vow *setInterval(int delay, std::function<void()> cb, Vow *vow);
Vow *nextTick(std::function<void()> cb);
void clearInterval(Vow *vow);
void clearTimeout(Vow *vow);
void start();
void stop();
};
#endif