|
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError, std::invocable<> OnCompleted> |
using | rpp::lambda_observer = observer<Type, details::observers::lambda_strategy<Type, OnNext, OnError, OnCompleted>> |
| Observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
|
|
|
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError = rpp::utils::rethrow_error_t, std::invocable<> OnCompleted = rpp::utils::empty_function_t<>> |
auto | rpp::make_lambda_observer (OnNext &&on_next, OnError &&on_error={}, OnCompleted &&on_completed={}) -> lambda_observer< Type, std::decay_t< OnNext >, std::decay_t< OnError >, std::decay_t< OnCompleted > > |
| Constructs observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
|
|
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError = rpp::utils::rethrow_error_t, std::invocable<> OnCompleted = rpp::utils::empty_function_t<>> |
auto | rpp::make_lambda_observer (const rpp::composite_disposable_wrapper &d, OnNext &&on_next, OnError &&on_error={}, OnCompleted &&on_completed={}) -> lambda_observer_with_external_disposable< Type, std::decay_t< OnNext >, std::decay_t< OnError >, std::decay_t< OnCompleted > > |
| Constructs observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
|
|
Observer subscribes on Observable and obtains values provided by Observable.
In fact observer is kind of wrapper over 3 core functions:
on_next(T)
- callback with new emission provided by observable
on_error(err)
- failure termination callback with reason of failure of observable (why observable can't continue processing)
on_completed()
- succeed termination callback - observable is done, no any future emissions from this
Additionally in RPP observer handles disposables related logic:
set_upstream(disposable)
- observable could pass to observer it's own disposable to provide ability for observer to terminate observable's internal actions/state.
is_disposed()
- observable could check if observer is still interested in emissions (false
) or done and no any futher calls would be success (true
)
- Observer creation:
- Observer creation inside subscribe:
RPP expects user to create observers only inside subscribe
function of observables. Something like this:
auto just(const TScheduler &scheduler, T &&item, Ts &&... items)
Creates rpp::observable that emits a particular items and completes.
Definition from.hpp:201
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition subscribe.hpp:226
Some of the callbacks (on_next/on_error/on_completed) can be omitted. Check rpp::operators::subscribe for more details.
- Advanced observer creation:
Technically it is possible to create custom observer via creating new class/struct which satisfies concept rpp::constraint::observer_strategy, but it is highly not-recommended for most cases
Also technically you could create your observer via make_lambda_observer
function, but it is not recommended too: it could disable some built-in optimizations and cause worse performance.
Also it is most probably bad pattern and invalid usage of RX if you want to keep/store observers as member variables/fields. Most probably you are doing something wrong IF you are not implementing custom observable/operator.
- See also
- https://reactivex.io/documentation/observable.html
◆ lambda_observer
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError, std::invocable<> OnCompleted>
Observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
- Template Parameters
-
Type | of value this observer can handle |
OnNext | is type of callback to handle on_next(const Type&) and on_next(Type&&) |
OnError | is type of callback to handle on_error(const std::exception_ptr&) |
OnCompleted | is type of callback to handle on_completed() |
◆ make_lambda_observer() [1/2]
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError = rpp::utils::rethrow_error_t, std::invocable<> OnCompleted = rpp::utils::empty_function_t<>>
Constructs observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
- Template Parameters
-
Type | of value this observer can handle |
- Parameters
-
d | is disposable to attach to resulting observer |
on_next | is callback to handle on_next(const Type&) and on_next(Type&&) |
on_error | is callback to handle on_error(const std::exception_ptr&) |
on_completed | is callback to handle on_completed() |
◆ make_lambda_observer() [2/2]
template<constraint::decayed_type Type, std::invocable< Type > OnNext, std::invocable< const std::exception_ptr & > OnError = rpp::utils::rethrow_error_t, std::invocable<> OnCompleted = rpp::utils::empty_function_t<>>
auto rpp::make_lambda_observer |
( |
OnNext && | on_next, |
|
|
OnError && | on_error = {}, |
|
|
OnCompleted && | on_completed = {} ) -> lambda_observer<Type,
std::decay_t<OnNext>,
std::decay_t<OnError>,
std::decay_t<OnCompleted>> |
Constructs observer specialized with passed callbacks. Most easiesest way to construct observer "on the fly" via lambdas and etc.
- Template Parameters
-
Type | of value this observer can handle |
- Parameters
-
on_next | is callback to handle on_next(const Type&) and on_next(Type&&) |
on_error | is callback to handle on_error(const std::exception_ptr&) |
on_completed | is callback to handle on_completed() |
- Examples
- readme.cpp.