ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
early_unsubscribe.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9
10#pragma once
11
12#include <rpp/subscriptions/composite_subscription.hpp>
13
14#include <exception>
15
16namespace rpp::details
17{
19{
20 early_unsubscribe_state(const composite_subscription& subscription_of_subscriber)
21 : children_subscriptions(subscription_of_subscriber.make_child()) {}
22
23 // use this subscription as source for any child subscription that should be early unsubscribed
24 composite_subscription children_subscriptions;
25};
26
28{
29 void operator()(const std::exception_ptr& err,
30 const constraint::subscriber auto& sub,
31 const std::shared_ptr<early_unsubscribe_state>& state) const
32 {
33 state->children_subscriptions.unsubscribe();
34 sub.on_error(err);
35 }
36};
37
39{
40 void operator()(const constraint::subscriber auto& sub,
41 const std::shared_ptr<early_unsubscribe_state>& state) const
42 {
43 state->children_subscriptions.unsubscribe();
44 sub.on_completed();
45 }
46};
47} // namespace rpp::details
rpp::subscription_base with ability to add some dependent subscriptions as a part of this one: in cas...
Definition: composite_subscription.hpp:30
Definition: constraints.hpp:19
Definition: early_unsubscribe.hpp:39
Definition: early_unsubscribe.hpp:28
Definition: early_unsubscribe.hpp:19