24 #include "log_enable.h" 40 Job(std::function<
void()>&& f) : do_(std::move(f)) {}
41 std::function<void()> do_;
42 void cancel() { do_ = {}; }
53 Sp<Scheduler::Job>
add(time_point t, std::function<
void()>&& job_func) {
54 auto job = std::make_shared<Job>(std::move(job_func));
55 if (t != time_point::max())
56 timers.emplace(std::move(t), job);
60 void add(
const Sp<Scheduler::Job>& job, time_point t) {
61 if (t != time_point::max())
62 timers.emplace(std::move(t), job);
71 void edit(Sp<Scheduler::Job>& job, time_point t) {
77 auto task = std::move(job->do_);
79 job =
add(t, std::move(task));
89 while (not timers.empty()) {
90 auto timer = timers.begin();
96 if (timer->first > now)
99 auto job = std::move(timer->second);
105 return getNextJobTime();
108 inline time_point getNextJobTime()
const {
109 return timers.empty() ? time_point::max() : timers.begin()->first;
116 inline const time_point&
time()
const {
return now; }
117 inline time_point syncTime() {
return (now = clock::now()); }
120 time_point now {clock::now()};
121 std::multimap<time_point, Sp<Job>> timers {};
Sp< Scheduler::Job > add(time_point t, std::function< void()> &&job_func)
const time_point & time() const
void edit(Sp< Scheduler::Job > &job, time_point t)