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

Function main

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

Source from the content-addressed store, hash-verified

9 **/
10
11int main() // NOLINT(bugprone-exception-escape)
12{
13 {
14 //! [fallback_observable]
15 auto start = rpp::schedulers::clock_type::now();
16
17 rpp::source::just(10, 30, 90, 110)
18 | rpp::operators::flat_map([](int v) {
19 return rpp::source::just(v) | rpp::operators::delay(std::chrono::milliseconds{v}, rpp::schedulers::current_thread{});
20 })
21 | rpp::operators::timeout(std::chrono::milliseconds{35}, rpp::source::just(rpp::schedulers::immediate{}, 0), rpp::schedulers::new_thread{})
22 | rpp::operators::as_blocking()
23 | rpp::operators::subscribe([start](int v) { std::cout << "received " << v << " at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl; },
24 [start](const std::exception_ptr&) {
25 std::cout << "received error at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl;
26 });
27 //! [fallback_observable]
28 }
29
30 {
31 //! [default]
32 auto start = rpp::schedulers::clock_type::now();
33
34 rpp::source::just(10, 30, 90, 110)
35 | rpp::operators::flat_map([](int v) {
36 return rpp::source::just(v) | rpp::operators::delay(std::chrono::milliseconds{v}, rpp::schedulers::current_thread{});
37 })
38 | rpp::operators::timeout(std::chrono::milliseconds{35}, rpp::schedulers::new_thread{})
39 | rpp::operators::as_blocking()
40 | rpp::operators::subscribe([start](int v) { std::cout << "received " << v << " at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl; },
41 [start](const std::exception_ptr&) {
42 std::cout << "received error at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl;
43 });
44 //! [default]
45 }
46}

Callers

nothing calls this directly

Calls 7

nowFunction · 0.85
justFunction · 0.85
flat_mapFunction · 0.85
delayFunction · 0.85
timeoutFunction · 0.85
as_blockingFunction · 0.85
subscribeFunction · 0.85

Tested by

no test coverage detected