ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
ref_count.cpp
#include <rpp/rpp.hpp>
#include <iostream>
int main() // NOLINT(bugprone-exception-escape)
{
{
auto observable = rpp::source::create<int>([](const auto& observer) {
std::cout << "SUBSCRIBE" << std::endl;
for (int i = 0; i < 3; ++i)
{
observer.on_next(i);
}
observer.on_completed();
})
std::cout << "subscribe first" << std::endl;
observable.subscribe([](int v) { std::cout << "#1 " << v << std::endl; });
// No Output
std::cout << "subscribe with ref_count" << std::endl;
observable.ref_count().subscribe([](int v) { std::cout << "#2 " << v << std::endl; });
// Output:
// subscribe first
// subscribe with ref_count
// SUBSCRIBE
// #1 0
// #2 0
// #1 1
// #2 1
// #1 2
// #2 2
}
{
auto observable = rpp::source::just(1, 2, 3) | rpp::operators::multicast();
observable.subscribe([](int v) { std::cout << "#1 " << v << std::endl; });
// No Output
observable | rpp::ops::ref_count() | rpp::ops::subscribe([](int v) { std::cout << "#2 " << v << std::endl; });
// Output:
// #1 1
// #2 1
// #1 2
// #2 2
// #1 3
// #2 3
}
return 0;
}
auto multicast()
Converts ordinary observable to rpp::connectable_observable with help of inline instsantiated subject...
Definition multicast.hpp:85
auto just(const TScheduler &scheduler, T &&item, Ts &&... items)
Creates rpp::observable that emits a particular items and completes.
Definition from.hpp:201
auto create(OnSubscribe &&on_subscribe)
Construct observable specialized with passed callback function. Most easiesest way to construct obser...
Definition create.hpp:57