ReactivePlusPlus
ReactiveX implementation for C++20
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{})
[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"; },
[]() { 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{})
[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"; },
[]() { 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
}
immediately calls provided schedulable or waits for time_point (in the caller-thread)
Definition immediate.hpp:65
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
auto take(size_t count)
Emit only first count items provided by observable, then send on_completed
Definition take.hpp:92
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition subscribe.hpp:226
Definition functors.hpp:54