A C++11 cross-platform Timer implementation on POSIX.
Can easy add a one-time timing task or repeat timing task.
addJobRunAt(expiration, cb_func, args...)
addJobRunAfter(duration, cb_func, args...)
addJobRunEvery(duration, cb_func, args...)
addJobRepeatAtDay(hour, minute, sec, cb_func, args...)
addJobRepeatAtHour(minute, sec, cb_func, args...)
addJobRepeatAtMinute(sec, cb_func, args...)
Just for
addJobRunAt
&addJobRunAfter
Example:
auto pair = timer->addJobRunAt(
system_clock::now(), for_test);
pair.second.wait();
auto result = pair.second.get();
Task can run in thread pool asynchronously.
ThreadPool tp;
ManagerTimer(&tp);
If tp == nullptr run task in timer thread.
ThreadPool need to supply 'enqueue' function to add task.
You can use dep/ThreadPool. Thanks for Jakob Progsch.
Read demo.cpp
can get it.
- Must link library
rt
&pthread
. ManagerTimer
must callinit()
&start
before add timing task.
Have Fun.