ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
on_error_resume_next.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// TC Wang 2022 - present.
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// https://www.boost.org/LICENSE_1_0.txt)
8//
9// Project home: https://github.com/victimsnino/ReactivePlusPlus
10//
11
12#pragma once
13
14#include <rpp/defs.hpp> // RPP_NO_UNIQUE_ADDRESS
15#include <rpp/operators/lift.hpp> // required due to operator uses lift
16#include <rpp/operators/details/subscriber_with_state.hpp> // create_subscriber_with_state
17#include <rpp/operators/fwd/on_error_resume_next.hpp> // own forwarduing
18#include <rpp/subscribers/constraints.hpp> // constraint::subscriber_of_type
19#include <rpp/utils/functors.hpp>
20
21IMPLEMENTATION_FILE(on_error_resume_next_tag);
22
23namespace rpp::details
24{
29{
30 template<rpp::details::resume_callable ResumeCallable>
31 void operator()(const std::exception_ptr& err,
32 const auto& subscriber,
33 const ResumeCallable& resume_callable) const
34 {
35 // Subscribe to next_observable
36 resume_callable(err).subscribe(subscriber);
37 }
38};
39
43template<constraint::decayed_type Type, rpp::details::resume_callable ResumeCallable>
45{
46 RPP_NO_UNIQUE_ADDRESS ResumeCallable resume_callable;
47
48 template<constraint::subscriber_of_type<Type> TSub>
49 auto operator()(TSub&& downstream_subscriber) const
50 {
51 // Child subscription is for keeping the downstream subscriber's subscription alive when upstream sends on_error event.
52 auto subscription = downstream_subscriber.get_subscription().make_child();
53
54 return create_subscriber_with_state<Type>(std::move(subscription),
55 rpp::utils::forwarding_on_next{},
57 rpp::utils::forwarding_on_completed{},
58 std::forward<TSub>(downstream_subscriber),
60 }
61};
62} // namespace rpp::details
Definition: on_error_resume_next.hpp:29
Functor of OperatorFn for "on_error_resume_next" operator (used by "lift").
Definition: on_error_resume_next.hpp:45
Definition: on_error_resume_next.hpp:29