-
Notifications
You must be signed in to change notification settings - Fork 7
/
timer_task.hxx
41 lines (36 loc) · 920 Bytes
/
timer_task.hxx
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
#ifndef _TIMER_TASK_HXX_
#define _TIMER_TASK_HXX_
namespace cornerstone {
template<typename T>
class timer_task : public delayed_task {
public:
typedef std::function<void(T)> executor;
timer_task(executor& e, T ctx)
: exec_(e), ctx_(ctx) {}
protected:
virtual void exec() __override__ {
if (exec_) {
exec_(ctx_);
}
}
private:
executor exec_;
T ctx_;
};
template<>
class timer_task<void> : public delayed_task {
public:
typedef std::function<void()> executor;
explicit timer_task(executor& e)
: exec_(e) {}
protected:
virtual void exec() __override__ {
if (exec_) {
exec_();
}
}
private:
executor exec_;
};
}
#endif //_TIMER_TASK_HXX_