5 #if !defined(RXCPP_RX_SCHEDULER_VIRTUAL_TIME_HPP) 6 #define RXCPP_RX_SCHEDULER_VIRTUAL_TIME_HPP 8 #include "../rx-includes.hpp" 12 namespace schedulers {
16 template<
class Absolute,
class Relative>
17 struct virtual_time_base : std::enable_shared_from_this<virtual_time_base<Absolute, Relative>>
20 typedef virtual_time_base<Absolute, Relative> this_type;
21 virtual_time_base(
const virtual_time_base&);
23 mutable bool isenabled;
26 typedef Absolute absolute;
27 typedef Relative relative;
29 virtual ~virtual_time_base()
39 explicit virtual_time_base(absolute initialClock)
41 , clock_now(initialClock)
45 mutable absolute clock_now;
47 typedef time_schedulable<long> item_type;
49 virtual absolute add(absolute, relative)
const =0;
51 virtual typename scheduler_base::clock_type::time_point to_time_point(absolute)
const =0;
52 virtual relative to_relative(
typename scheduler_base::clock_type::duration)
const =0;
54 virtual item_type top()
const =0;
55 virtual void pop()
const =0;
56 virtual bool empty()
const =0;
60 virtual void schedule_absolute(absolute,
const schedulable&)
const =0;
62 virtual void schedule_relative(relative when,
const schedulable& a)
const {
63 auto at = add(clock_now, when);
64 return schedule_absolute(at, a);
67 bool is_enabled()
const {
return isenabled;}
68 absolute clock()
const {
return clock_now;}
76 while (!
empty() && isenabled) {
79 if (next.what.is_subscribed()) {
80 if (next.when > clock_now) {
81 clock_now = next.when;
83 next.what(r.get_recurse());
95 void advance_to(absolute time)
const 97 if (time < clock_now) {
101 if (time == clock_now) {
108 while (!
empty() && isenabled) {
110 if (next.when <= time) {
112 if (!next.what.is_subscribed()) {
115 if (next.when > clock_now) {
116 clock_now = next.when;
118 next.what(r.get_recurse());
132 void advance_by(relative time)
const 134 auto dt = add(clock_now, time);
136 if (dt < clock_now) {
140 if (dt == clock_now) {
152 void sleep(relative time)
const 154 auto dt = add(clock_now, time);
156 if (dt < clock_now) {
167 template<
class Absolute,
class Relative>
168 struct virtual_time :
public detail::virtual_time_base<Absolute, Relative>
170 typedef detail::virtual_time_base<Absolute, Relative>
base;
174 typedef detail::schedulable_queue<
177 mutable queue_item_time
q;
193 virtual item_type
top()
const {
196 virtual void pop()
const {
203 using base::schedule_absolute;
204 using base::schedule_relative;
215 if (scbl.is_subscribed()) {
220 q.push(item_type(when, run));
void reset(bool b=true) const
set whether tail-recursion is allowed
Definition: rx-scheduler.hpp:112
Definition: rx-all.hpp:26
controls lifetime for scheduler::schedule and observable<T, SourceOperator>::subscribe.
Definition: rx-subscription.hpp:364
virtual ~virtual_time()
Definition: rx-virtualtime.hpp:180
auto make_schedulable(const schedulable &scbl) -> schedulable
Definition: rx-scheduler.hpp:735
virtual_time()
Definition: rx-virtualtime.hpp:185
base::item_type item_type
Definition: rx-virtualtime.hpp:172
auto empty() -> decltype(from< T >())
Returns an observable that sends no items to observer and immediately completes, on the specified sch...
Definition: rx-empty.hpp:37
virtual void pop() const
Definition: rx-virtualtime.hpp:196
virtual bool empty() const
Definition: rx-virtualtime.hpp:199
detail::virtual_time_base< Absolute, Relative > base
Definition: rx-virtualtime.hpp:170
queue_item_time q
Definition: rx-virtualtime.hpp:177
recursion is used by the scheduler to signal to each action whether tail recursion is allowed...
Definition: rx-scheduler.hpp:95
virtual_time(typename base::absolute initialClock)
Definition: rx-virtualtime.hpp:188
virtual item_type top() const
Definition: rx-virtualtime.hpp:193
const recurse & get_recurse() const
get the recurse to pass into each action being called
Definition: rx-scheduler.hpp:116
detail::schedulable_queue< typename item_type::time_point_type > queue_item_time
Definition: rx-virtualtime.hpp:175
const worker get_worker() const
Definition: rx-scheduler.hpp:544
virtual void schedule_absolute(typename base::absolute when, const schedulable &a) const
Definition: rx-virtualtime.hpp:206
Definition: rx-virtualtime.hpp:168
Definition: rx-scheduler.hpp:426