23 Job(std::function<
void()>&& f, time_point t)
27 std::function<void()> do_;
29 void cancel() { do_ = {}; }
40 Sp<Scheduler::Job>
add(time_point t, std::function<
void()>&& job_func)
42 auto job = std::make_shared<Job>(std::move(job_func), t);
43 if (t != time_point::max())
44 timers.emplace(std::move(t), job);
54 void edit(Sp<Scheduler::Job>& job, time_point t)
60 auto task = std::move(job->do_);
62 job =
add(t, std::move(task));
65 bool cancel(Sp<Scheduler::Job>& job)
69 for (
auto r = timers.equal_range(job->t_); r.first != r.second; ++r.first) {
70 if (r.first->second == job) {
71 timers.erase(r.first);
87 while (not timers.empty()) {
88 auto timer = timers.begin();
94 if (timer->first > now)
97 auto job = std::move(timer->second);
103 return getNextJobTime();
106 inline time_point getNextJobTime()
const {
return timers.empty() ? time_point::max() : timers.begin()->first; }
112 inline const time_point&
time()
const {
return now; }
113 inline time_point syncTime() {
return (now = clock::now()); }
114 inline void syncTime(
const time_point& n) { now = n; }
117 time_point now {clock::now()};
118 std::multimap<time_point, Sp<Job>> timers {};