39 Job(std::function<
void()>&& f, time_point t) : do_(std::move(f)), t_(t) {}
40 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), t);
55 if (t != time_point::max())
56 timers.emplace(std::move(t), job);
66 void edit(Sp<Scheduler::Job>& job, time_point t) {
71 auto task = std::move(job->do_);
73 job =
add(t, std::move(task));
76 bool cancel(Sp<Scheduler::Job>& job) {
79 for (
auto r = timers.equal_range(job->t_); r.first != r.second; ++r.first) {
80 if (r.first->second == job) {
81 timers.erase(r.first);
96 while (not timers.empty()) {
97 auto timer = timers.begin();
103 if (timer->first > now)
106 auto job = std::move(timer->second);
112 return getNextJobTime();
115 inline time_point getNextJobTime()
const {
116 return timers.empty() ? time_point::max() : timers.begin()->first;
123 inline const time_point&
time()
const {
return now; }
124 inline time_point syncTime() {
return (now = clock::now()); }
125 inline void syncTime(
const time_point& n) { now = n; }
128 time_point now {clock::now()};
129 std::multimap<time_point, Sp<Job>> timers {};