12#include <rpp/schedulers/fwd.hpp>
13#include <rpp/subjects/fwd.hpp>
15#include <rpp/disposables/disposable_wrapper.hpp>
16#include <rpp/observers/observer.hpp>
17#include <rpp/subjects/details/subject_on_subscribe.hpp>
18#include <rpp/subjects/details/subject_state.hpp>
22namespace rpp::subjects::details
24 template<rpp::constra
int::decayed_type Type,
bool Serialized>
27 class behavior_state final :
public subject_state<Type, Serialized>
30 behavior_state(
const Type& v)
34 behavior_state(Type&& v)
35 : m_value{std::move(v)}
39 rpp::utils::pointer_under_lock<Type> get_value() {
return rpp::utils::pointer_under_lock<Type>{m_value}; }
45 struct observer_strategy
47 static constexpr auto preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
49 std::shared_ptr<behavior_state> state;
53 bool is_disposed()
const noexcept {
return state->is_disposed(); }
55 void on_next(
const Type& v)
const
57 *state->get_value() = v;
61 void on_error(
const std::exception_ptr& err)
const { state->on_error(err); }
63 void on_completed()
const { state->on_completed(); }
79 auto get_observer()
const
84 auto get_observable()
const
87 const auto locked = state.lock();
88 if (!locked->is_disposed())
90 auto v = *locked->get_value();
93 locked->on_subscribe(std::forward<TObs>(
observer));
102 Type get_value()
const
104 return *m_state.lock()->get_value();
113namespace rpp::subjects
123 template<rpp::constra
int::decayed_type Type>
137 template<rpp::constra
int::decayed_type Type>
138 class serialized_behavior_subject final :
public details::behavior_subject_base<Type, true>
141 using details::behavior_subject_base<Type,
true>::behavior_subject_base;
void on_next(const Type &v) const noexcept
Observable calls this method to notify observer about new value.
Definition observer.hpp:84
static disposable_wrapper_impl make(TArgs &&... args)
Main way to create disposable_wrapper. Passed TTarget type can be any type derived from TDisposable.
Definition disposable_wrapper.hpp:164
Base class for any observer used in RPP. It handles core callbacks of observers. Objects of this clas...
Definition observer.hpp:172
Same as rpp::subjects::publish_subject but keeps last value (or default) and emits it to newly subscr...
Definition fwd.hpp:36
Definition behavior_subject.hpp:26
Definition subject_state.hpp:41
Definition disposables_strategy.hpp:29