ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
defer.cpp
#include <rpp/rpp.hpp>
#include <iostream>
int main() // NOLINT(bugprone-exception-escape)
{
std::cout << "Observable factory called\n";
return rpp::source::from_iterable(std::array{ 1,2,3 }); })
.subscribe([](int v) { std::cout << v << "\n"; }, rpp::utils::rethrow_error_t{}, []() { std::cout << "On complete\n"; });
// Output: Observable factory called
// 1
// 2
// 3
// On complete
auto obs = rpp::source::defer([] {
std::cout << "Observable factory called\n";
const auto state = std::make_shared<int>(0);
auto inner_obs = rpp::source::create<int>([state](const auto& obs) {
obs.on_next((*state)++);
obs.on_completed();
});
return inner_obs;
});
obs.subscribe([](int v) { std::cout << v << "\n"; }, rpp::utils::rethrow_error_t{}, []() { std::cout << "On complete\n"; });
obs.subscribe([](int v) { std::cout << v << "\n"; }, rpp::utils::rethrow_error_t{}, []() { std::cout << "On complete\n"; });
// Output: Observable factory called
// 0
// On complete
// Observable factory called
// 0
// On complete
}
auto from_iterable(Iterable &&iterable, const TScheduler &scheduler)
Creates observable that emits a items from provided iterable.
Definition from.hpp:175
auto defer(Factory &&observable_factory)
Creates rpp::observable that calls the specified observable factory to create an observable for each ...
Definition defer.hpp:57
auto create(OnSubscribe &&on_subscribe)
Construct observable specialized with passed callback function. Most easiesest way to construct obser...
Definition create.hpp:57
Definition functors.hpp:54