13#include <rpp/schedulers/constraints.hpp>
14#include <rpp/schedulers/fwd.hpp>
15#include <rpp/utils/constraints.hpp>
20namespace rpp::schedulers
25 t.defer_at(time_point{}, std::declval<optional_duration(*)()>());
26 { t.now() } -> std::same_as<time_point>;
29template<
typename Strategy>
33 template<constra
int::schedulable_fn Fn>
35 : m_strategy{strategy}
36 , m_time_point{time_point}
37 , m_fn{std::forward<Fn>(fn)} {}
41 if (!m_strategy.is_subscribed())
44 if (
const auto duration = m_fn())
46 m_time_point = std::max(m_strategy.now(), m_time_point + duration.value());
48 m_strategy.defer_at(m_time_point, std::move(*
this));
54 time_point m_time_point;
55 std::function<optional_duration()> m_fn{};
58template<worker_strategy Strategy>
62 template<
typename ...Args>
63 requires (!rpp::constraint::variadic_is_same_type<worker<Strategy>, Args...>)
64 worker(Args&& ...args) : m_strategy{std::forward<Args>(args)...} {}
68 schedule(m_strategy.now(), std::forward<
decltype(fn)>(fn));
73 schedule(m_strategy.now() + delay, std::forward<
decltype(fn)>(fn));
78 m_strategy.defer_at(time_point, std::forward<
decltype(fn)>(fn));
81 static time_point now() {
return Strategy::now(); }
Definition: worker.hpp:31
Definition: worker.hpp:60
Definition: constraints.hpp:22
Definition: worker.hpp:23