ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
subscription_state.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 <atomic>
14
15namespace rpp::details
16{
22{
23public:
24 subscription_state() = default;
25 virtual ~subscription_state() = default;
26
28 subscription_state(subscription_state&&) noexcept = delete;
29
30 [[nodiscard]] bool is_subscribed() const
31 {
32 return m_is_subscribed.load();
33 }
34
35 void unsubscribe()
36 {
37 if (m_is_subscribed.exchange(false))
39 }
40
41protected:
45 virtual void on_unsubscribe() {}
46
47private:
48 std::atomic_bool m_is_subscribed{true};
49};
50} // namespace rpp::details
Base implementation of subscription state used under-hood for rpp::subscription_base and its childs.
Definition: subscription_state.hpp:22
virtual void on_unsubscribe()
Derrived action on unsubscribe. Will be called only ONCE!
Definition: subscription_state.hpp:45