RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
rx-immediate.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 
3 #pragma once
4 
5 #if !defined(RXCPP_RX_SCHEDULER_IMMEDIATE_HPP)
6 #define RXCPP_RX_SCHEDULER_IMMEDIATE_HPP
7 
8 #include "../rx-includes.hpp"
9 
10 namespace rxcpp {
11 
12 namespace schedulers {
13 
15 {
16 private:
17  typedef immediate this_type;
18  immediate(const this_type&);
19 
20  struct immediate_worker : public worker_interface
21  {
22  private:
23  typedef immediate_worker this_type;
24  immediate_worker(const this_type&);
25  public:
26  virtual ~immediate_worker()
27  {
28  }
29  immediate_worker()
30  {
31  }
32 
33  virtual clock_type::time_point now() const {
34  return clock_type::now();
35  }
36 
37  virtual void schedule(const schedulable& scbl) const {
38  if (scbl.is_subscribed()) {
39  // allow recursion
40  recursion r(true);
41  scbl(r.get_recurse());
42  }
43  }
44 
45  virtual void schedule(clock_type::time_point when, const schedulable& scbl) const {
46  std::this_thread::sleep_until(when);
47  if (scbl.is_subscribed()) {
48  // allow recursion
49  recursion r(true);
50  scbl(r.get_recurse());
51  }
52  }
53  };
54 
55  std::shared_ptr<immediate_worker> wi;
56 
57 public:
59  : wi(std::make_shared<immediate_worker>())
60  {
61  }
62  virtual ~immediate()
63  {
64  }
65 
66  virtual clock_type::time_point now() const {
67  return clock_type::now();
68  }
69 
71  return worker(std::move(cs), wi);
72  }
73 };
74 
75 inline const scheduler& make_immediate() {
76  static scheduler instance = make_scheduler<immediate>();
77  return instance;
78 }
79 
80 }
81 
82 }
83 
84 #endif
virtual worker create_worker(composite_subscription cs) const
Definition: rx-immediate.hpp:70
Definition: rx-scheduler.hpp:163
Definition: rx-all.hpp:26
bool is_subscribed() const
Definition: rx-scheduler.hpp:585
controls lifetime for scheduler::schedule and observable<T, SourceOperator>::subscribe.
Definition: rx-subscription.hpp:364
virtual ~immediate()
Definition: rx-immediate.hpp:62
virtual clock_type::time_point now() const
Definition: rx-immediate.hpp:66
allows functions to be called at specified times and possibly in other contexts.
Definition: rx-scheduler.hpp:383
recursion is used by the scheduler to signal to each action whether tail recursion is allowed...
Definition: rx-scheduler.hpp:95
const recurse & get_recurse() const
get the recurse to pass into each action being called
Definition: rx-scheduler.hpp:116
Definition: rx-scheduler.hpp:353
Definition: rx-immediate.hpp:14
immediate()
Definition: rx-immediate.hpp:58
Definition: rx-scheduler.hpp:426
const scheduler & make_immediate()
Definition: rx-immediate.hpp:75
Definition: rx-scheduler.hpp:200