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

Function main

src/examples/rpp/doxygen/window_toggle.cpp:8–44  ·  view source on GitHub ↗

* @example window_toggle.cpp **/

Source from the content-addressed store, hash-verified

6 * @example window_toggle.cpp
7 **/
8int main()
9{
10
11 //! [window_toggle]
12 size_t counter{};
13 auto source = rpp::source::just(rpp::schedulers::current_thread{}, 1, 2, 3, 4, 5) | rpp::operators::publish() | rpp::operators::ref_count();
14 source
15 | rpp::operators::window_toggle(source, [source](int) { return source | rpp::ops::filter([](int v) { return v % 2 == 0; }); })
16 | rpp::operators::subscribe([&counter](const rpp::window_toggle_observable<int>& obs) {
17 std::cout << "New observable " << ++counter << std::endl;
18 obs.subscribe([counter](int v) { std::cout << counter << ": " << v << " " << std::endl; }, [counter]() { std::cout << "closing " << counter << std::endl; });
19 });
20 // Output:
21 // New observable 1
22 // 1: 1
23 // New observable 2
24 // 1: 2
25 // 2: 2
26 // closing 1
27 // New observable 3
28 // 2: 3
29 // 3: 3
30 // New observable 4
31 // 2: 4
32 // 3: 4
33 // 4: 4
34 // closing 2
35 // closing 3
36 // New observable 5
37 // 4: 5
38 // 5: 5
39 // closing 4
40 // closing 5
41 //! [window_toggle]
42
43 return 0;
44}

Callers

nothing calls this directly

Calls 7

justFunction · 0.85
publishFunction · 0.85
ref_countFunction · 0.85
window_toggleFunction · 0.85
filterFunction · 0.85
subscribeFunction · 0.85
subscribeMethod · 0.45

Tested by

no test coverage detected