13#include <rpp/observers/fwd.hpp>
15#include <rpp/defs.hpp>
16#include <rpp/disposables/composite_disposable.hpp>
17#include <rpp/disposables/disposable_wrapper.hpp>
18#include <rpp/observers/details/disposables_strategy.hpp>
19#include <rpp/utils/exceptions.hpp>
20#include <rpp/utils/functors.hpp>
21#include <rpp/utils/utils.hpp>
27 template<constra
int::decayed_type Type, constra
int::observer_strategy<Type> Strategy, observers::constra
int::disposables_strategy DisposablesStrategy>
31 template<
typename... Args>
33 explicit observer_impl(DisposablesStrategy strategy, Args&&... args)
34 : m_strategy{std::forward<Args>(args)...}
35 , m_disposable{std::move(strategy)}
40 static constexpr auto preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
42 using on_next_lvalue = void (observer_impl::*)(
const Type&)
const noexcept;
43 using on_next_rvalue = void (observer_impl::*)(Type&&)
const noexcept;
60 m_strategy.set_upstream(d);
76 return m_disposable.is_disposed() || m_strategy.is_disposed();
84 void on_next(
const Type& v)
const noexcept
89 m_strategy.on_next(v);
107 m_strategy.on_next(std::move(v));
120 void on_error(
const std::exception_ptr& err)
const noexcept
125 m_disposable.dispose();
127 m_strategy.on_error(err);
140 m_disposable.dispose();
142 m_strategy.on_completed();
147 RPP_NO_UNIQUE_ADDRESS Strategy m_strategy;
148 RPP_NO_UNIQUE_ADDRESS
mutable DisposablesStrategy m_disposable;
167 template<constra
int::decayed_type Type, constra
int::observer_strategy<Type> Strategy>
170 template<constra
int::decayed_type Type, constra
int::observer_strategy<Type> Strategy>
171 class observer final :
public details::observer_impl<Type, Strategy, details::observers::deduce_optimal_disposables_strategy_t<Strategy::preferred_disposables_mode>>
174 using DisposableStrategy = details::observers::deduce_optimal_disposables_strategy_t<Strategy::preferred_disposables_mode>;
177 template<
typename... Args>
179 explicit observer(DisposableStrategy strategy, Args&&... args)
180 : Base{std::move(strategy), std::forward<Args>(args)...}
184 template<
typename... Args>
186 explicit observer(Args&&... args)
187 : Base{DisposableStrategy{}, std::forward<Args>(args)...}
191 observer(
const observer&) =
delete;
192 observer(observer&&)
noexcept =
default;
203 template<constra
int::decayed_type Type, constra
int::observer_strategy<Type> Strategy, rpp::details::observers::constra
int::disposables_strategy DisposableStrategy>
204 class observer<Type, details::observers::override_disposables_strategy<Strategy, DisposableStrategy>> final :
public details::observer_impl<Type, Strategy, DisposableStrategy>
209 template<
typename... Args>
211 explicit observer(DisposableStrategy strategy, Args&&... args)
212 : Base{std::move(strategy), std::forward<Args>(args)...}
216 template<
typename... Args>
218 explicit observer(Args&&... args)
219 : Base{DisposableStrategy{}, std::forward<Args>(args)...}
223 observer(
const observer&) =
delete;
224 observer(observer&&)
noexcept =
default;
235 template<constra
int::decayed_type Type>
237 :
public details::observer_impl<Type, rpp::details::observers::dynamic_strategy<Type>, details::observers::none_disposables_strategy>
240 template<constra
int::observer_strategy<Type> TStrategy>
241 requires (!std::same_as<TStrategy, rpp::details::observers::dynamic_strategy<Type>>)
242 observer(observer<Type, TStrategy>&& other)
Definition observer.hpp:29
void on_next(const Type &v) const noexcept
Observable calls this method to notify observer about new value.
Definition observer.hpp:84
void set_upstream(const disposable_wrapper &d) noexcept
Observable calls this method to pass disposable. Observer disposes this disposable WHEN observer want...
Definition observer.hpp:49
void on_next(Type &&v) const noexcept
Observable calls this method to notify observer about new value.
Definition observer.hpp:102
void on_completed() const noexcept
Observable calls this method to notify observer about completion of emissions.
Definition observer.hpp:135
void on_error(const std::exception_ptr &err) const noexcept
Observable calls this method to notify observer about some error during generation next data.
Definition observer.hpp:120
bool is_disposed() const noexcept
Observable calls this method to check if observer interested or not in emissions.
Definition observer.hpp:74
Definition dynamic_observer.hpp:92
Type-erased version of the rpp::observer. Any observer can be converted to dynamic_observer via rpp::...
Definition dynamic_observer.hpp:129
dynamic_observer< Type > as_dynamic() &&
Convert current observer to type-erased version. Useful if you need to COPY your observer or to store...
Definition observer.hpp:229
dynamic_observer< Type > as_dynamic() &&
Convert current observer to type-erased version. Useful if you need to COPY your observer or to store...
Definition observer.hpp:197
Calls passed function during destruction.
Definition utils.hpp:120
Definition constraints.hpp:43
Definition constraints.hpp:31
disposable_wrapper_impl< interface_disposable > disposable_wrapper
Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition fwd.hpp:34
Definition disposables_strategy.hpp:51