2424// Usage:
2525//
2626// CScheduler* s = new CScheduler();
27- // s->scheduleFromNow(doSomething, 11 ); // Assuming a: void doSomething() { }
28- // s->scheduleFromNow(std::bind(Class::func, this, argument), 3 );
27+ // s->scheduleFromNow(doSomething, std::chrono::milliseconds{11} ); // Assuming a: void doSomething() { }
28+ // s->scheduleFromNow([=] { this->func( argument); }, std::chrono::milliseconds{3} );
2929// boost::thread* t = new boost::thread(std::bind(CScheduler::serviceQueue, s));
3030//
3131// ... then at program shutdown, make sure to call stop() to clean up the thread(s) running serviceQueue:
@@ -46,15 +46,19 @@ class CScheduler
4646 // Call func at/after time t
4747 void schedule (Function f, std::chrono::system_clock::time_point t);
4848
49- // Convenience method: call f once deltaMilliSeconds from now
50- void scheduleFromNow (Function f, int64_t deltaMilliSeconds);
49+ /* * Call f once after the delta has passed */
50+ void scheduleFromNow (Function f, std::chrono::milliseconds delta)
51+ {
52+ schedule (std::move (f), std::chrono::system_clock::now () + delta);
53+ }
5154
52- // Another convenience method: call f approximately
53- // every deltaMilliSeconds forever, starting deltaMilliSeconds from now.
54- // To be more precise: every time f is finished, it
55- // is rescheduled to run deltaMilliSeconds later. If you
56- // need more accurate scheduling, don't use this method.
57- void scheduleEvery (Function f, int64_t deltaMilliSeconds);
55+ /* *
56+ * Repeat f until the scheduler is stopped. First run is after delta has passed once.
57+ *
58+ * The timing is not exact: Every time f is finished, it is rescheduled to run again after delta. If you need more
59+ * accurate scheduling, don't use this method.
60+ */
61+ void scheduleEvery (Function f, std::chrono::milliseconds delta);
5862
5963 /* *
6064 * Mock the scheduler to fast forward in time.
0 commit comments