• 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_SAME_WORKER_HPP)
6 #define RXCPP_RX_SCHEDULER_SAME_WORKER_HPP
7 
8 #include "../rx-includes.hpp"
9 
10 namespace rxcpp {
11 
12 namespace schedulers {
13 
14 struct same_worker : public scheduler_interface
15 {
16 private:
17     typedef same_worker this_type;
18     same_worker(const this_type&);
19 
20     rxsc::worker controller;
21 
22 public:
same_workerrxcpp::schedulers::same_worker23     explicit same_worker(rxsc::worker w)
24         : controller(std::move(w))
25     {
26     }
~same_workerrxcpp::schedulers::same_worker27     virtual ~same_worker()
28     {
29     }
30 
nowrxcpp::schedulers::same_worker31     virtual clock_type::time_point now() const {
32         return controller.now();
33     }
34 
create_workerrxcpp::schedulers::same_worker35     virtual worker create_worker(composite_subscription cs) const {
36         // use different lifetime
37         auto inner_lifetime = controller.get_subscription();
38         auto token = inner_lifetime.add(cs);
39         cs.add([inner_lifetime, token](){inner_lifetime.remove(token);});
40         return worker(cs, controller);
41     }
42 };
43 
make_same_worker(rxsc::worker w)44 inline scheduler make_same_worker(rxsc::worker w) {
45     return make_scheduler<same_worker>(std::move(w));
46 }
47 
48 }
49 
50 }
51 
52 #endif
53