• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 struct immediate : public scheduler_interface
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:
~immediate_workerrxcpp::schedulers::immediate::immediate_worker26         virtual ~immediate_worker()
27         {
28         }
immediate_workerrxcpp::schedulers::immediate::immediate_worker29         immediate_worker()
30         {
31         }
32 
nowrxcpp::schedulers::immediate::immediate_worker33         virtual clock_type::time_point now() const {
34             return clock_type::now();
35         }
36 
schedulerxcpp::schedulers::immediate::immediate_worker37         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 
schedulerxcpp::schedulers::immediate::immediate_worker45         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:
immediaterxcpp::schedulers::immediate58     immediate()
59         : wi(std::make_shared<immediate_worker>())
60     {
61     }
~immediaterxcpp::schedulers::immediate62     virtual ~immediate()
63     {
64     }
65 
nowrxcpp::schedulers::immediate66     virtual clock_type::time_point now() const {
67         return clock_type::now();
68     }
69 
create_workerrxcpp::schedulers::immediate70     virtual worker create_worker(composite_subscription cs) const {
71         return worker(std::move(cs), wi);
72     }
73 };
74 
make_immediate()75 inline const scheduler& make_immediate() {
76     static scheduler instance = make_scheduler<immediate>();
77     return instance;
78 }
79 
80 }
81 
82 }
83 
84 #endif
85