30 void schedule(rpp::schedulers::time_point time_point, Fn&& fn, Handler&& handler, Args&&... args)
32 schedulings.push_back(time_point);
33 queue.emplace(time_point, std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
38 while (!queue.is_empty())
40 if (queue.top()->get_timepoint() > s_current_time)
43 auto fn = queue.top();
46 if (fn->is_disposed())
49 executions.push_back(s_current_time);
50 if (
auto new_timepoint = (*fn)())
52 if (fn->is_disposed())
55 schedulings.push_back(std::max(s_current_time, new_timepoint.value()));
56 queue.emplace(schedulings.back(), std::move(fn));
61 std::vector<rpp::schedulers::time_point> schedulings{};
62 std::vector<rpp::schedulers::time_point> executions{};
70 : m_state{std::move(
state)}
75 void defer_for(rpp::schedulers::duration duration, Fn&& fn, Handler&& handler, Args&&... args)
const
77 if (
auto locked = m_state.lock())
79 locked->schedule(now() + duration, std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
84 static rpp::schedulers::time_point now() {
return s_current_time; }
87 std::weak_ptr<state> m_state;