ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
subscriber_base.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
11#pragma once
12
13#include <rpp/subscriptions/composite_subscription.hpp>
14#include <rpp/subscriptions/subscription_guard.hpp>
15
16namespace rpp::details
17{
23{
24public:
26 : m_subscription{ std::move(subscription) } { }
27
28 subscriber_base(const composite_subscription& subscription)
29 : m_subscription{subscription}{ }
30
31
32 const composite_subscription& get_subscription() const
33 {
34 return m_subscription;
35 }
36
37 [[nodiscard]] bool is_subscribed() const
38 {
39 return m_subscription.is_subscribed();
40 }
41
42 void unsubscribe() const
43 {
44 m_subscription.unsubscribe();
45 }
46
47protected:
48 void do_if_subscribed_and_unsubscribe(const auto& callable) const
49 {
50 if (!is_subscribed())
51 return;
52
53 subscription_guard guard{m_subscription};
54 callable();
55 }
56
57private:
58 composite_subscription m_subscription{};
59};
60} // 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
base implementation of subscriber with possibility to obtain observer's callbacks,...
Definition: subscriber_base.hpp:23
bool is_subscribed() const
indicates current status of subscription
Definition: subscription_base.hpp:51
void unsubscribe() const
initiates unsubscription process (if subscribed)
Definition: subscription_base.hpp:59
guard over subscription to auto-unsubscribe during destructor
Definition: subscription_guard.hpp:21