ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
interval.cpp
#include <rpp/rpp.hpp>
#include <chrono>
#include <iostream>
int
main()
// NOLINT(bugprone-exception-escape)
{
rpp::source::interval
(std::chrono::milliseconds(10),
rpp::schedulers::immediate
{})
|
rpp::operators::take
(3)
|
rpp::operators::subscribe
(
[start = rpp::schedulers::clock_type::now()](
size_t
v) { std::cout <<
"emit "
<< v <<
" duration since start "
<< std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() <<
"ms\n"
; },
rpp::utils::rethrow_error_t
{},
[]() { std::cout <<
"On complete\n"
; });
// Output: Observable factory called
// emit 1 duration since start 0ms
// emit 2 duration since start 10ms
// emit 3 duration since start 20ms
// On complete
rpp::source::interval
(std::chrono::milliseconds(5), std::chrono::milliseconds(10),
rpp::schedulers::immediate
{})
|
rpp::operators::take
(3)
|
rpp::operators::subscribe
(
[start = rpp::schedulers::clock_type::now()](
size_t
v) { std::cout <<
"emit "
<< v <<
" duration since start "
<< std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() <<
"ms\n"
; },
rpp::utils::rethrow_error_t
{},
[]() { std::cout <<
"On complete\n"
; });
// Output: Observable factory called
// emit 1 duration since start 5ms
// emit 2 duration since start 15ms
// emit 3 duration since start 25ms
// On complete
}
rpp::schedulers::immediate
immediately calls provided schedulable or waits for time_point (in the caller-thread)
Definition
immediate.hpp:65
rpp::source::interval
auto interval(rpp::schedulers::duration initial, rpp::schedulers::duration period, TScheduler &&scheduler)
Creates rpp::observable that emits a sequential integer every specified time interval,...
Definition
interval.hpp:72
rpp::operators::take
auto take(size_t count)
Emit only first count items provided by observable, then send on_completed.
Definition
take.hpp:92
rpp::operators::subscribe
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition
subscribe.hpp:226
rpp::utils::rethrow_error_t
Definition
functors.hpp:54
Generated by
1.17.0