13#include <rpp/operators/fwd.hpp>
15#include <rpp/defs.hpp>
16#include <rpp/operators/details/strategy.hpp>
18namespace rpp::operators::details
20 template<rpp::constra
int::observer TObserver, constra
int::decayed_type Observable>
31 std::optional<size_t> count;
32 std::atomic<bool> is_inside_drain{};
34 RPP_NO_UNIQUE_ADDRESS TObserver
observer;
38 template<rpp::constra
int::observer TObserver,
typename TObservable>
41 template<rpp::constra
int::observer TObserver,
typename TObservable>
44 static constexpr auto preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
46 std::shared_ptr<retry_state_t<TObserver, TObservable>> state;
47 mutable bool locally_disposed{};
50 void on_next(T&& v)
const
52 state->observer.on_next(std::forward<T>(v));
55 void on_error(
const std::exception_ptr& err)
const
57 locally_disposed =
true;
58 if (state->count == 0)
60 state->observer.on_error(err);
66 if (state->is_inside_drain.exchange(
false, std::memory_order::seq_cst))
72 void on_completed()
const
74 locally_disposed =
true;
75 state->observer.on_completed();
83 bool is_disposed()
const {
return locally_disposed || state->is_disposed(); }
86 template<rpp::constra
int::observer TObserver,
typename TObservable>
89 while (!state->is_disposed())
92 --state->count.value();
93 state->is_inside_drain.store(
true, std::memory_order::seq_cst);
96 using value_type = rpp::utils::extract_observer_type_t<TObserver>;
99 if (state->is_inside_drain.exchange(
false, std::memory_order::seq_cst))
104 state->observer.on_error(std::current_exception());
112 const std::optional<size_t> count{};
114 template<rpp::constra
int::decayed_type T>
117 using result_type = T;
120 template<rpp::details::observables::constra
int::disposables_strategy Prev>
123 template<rpp::constra
int::observer TObserver,
typename TObservable>
124 void subscribe(TObserver&&
observer, TObservable&& observble)
const
129 ptr->observer.set_upstream(d.as_weak());
135namespace rpp::operators
156 inline auto retry(
size_t count)
158 return details::retry_t{count};
180 return details::retry_t{};
Disposable which can keep some other sub-disposables. When this root disposable is disposed,...
Definition composite_disposable.hpp:175
Base class for any observable used in RPP. It handles core callbacks of observable.
Definition observable.hpp:38
Base class for any observer used in RPP. It handles core callbacks of observers. Objects of this clas...
Definition observer.hpp:172
auto retry()
The infinite retry operator continuously attempts to resubscribe to the observable upon error,...
Definition retry.hpp:170
Definition disposables_strategy.hpp:29