MCPcopy Create free account
hub / github.com/AlexInLog/ReactivePlusPlus / main

Function main

src/examples/rpp/doxygen/connect.cpp:11–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 **/
10
11int main() // NOLINT(bugprone-exception-escape)
12{
13 //! [connect]
14 const auto observable = rpp::source::interval(std::chrono::milliseconds{50}, rpp::schedulers::new_thread{})
15 | rpp::ops::map([](int v) {
16 std::cout << "value in map" << v << std::endl;
17 return v;
18 })
19 | rpp::ops::publish();
20
21 std::cout << "CONNECT" << std::endl;
22 auto d = observable.connect(); // subscribe happens right now
23
24 std::this_thread::sleep_for(std::chrono::milliseconds{150});
25
26 std::cout << "SUBSCRIBE" << std::endl;
27 observable.subscribe([](int v) { std::cout << "observer value " << v << std::endl; });
28
29 std::this_thread::sleep_for(std::chrono::milliseconds{150});
30
31 d.dispose();
32 std::cout << "DISPOSE" << std::endl;
33
34 std::this_thread::sleep_for(std::chrono::milliseconds{150});
35
36 // possible output:
37 // CONNECT
38 // value in map0
39 // value in map1
40 // value in map2
41 // SUBSCRIBE
42 // value in map3
43 // observer value 3
44 // value in map4
45 // observer value 4
46 // value in map5
47 // observer value 5
48 // DISPOSE
49 //! [connect]
50}

Callers

nothing calls this directly

Calls 6

intervalFunction · 0.85
mapFunction · 0.85
publishFunction · 0.85
connectMethod · 0.80
subscribeMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected