ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
subscription_guard.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/subscription_base.hpp>
14
15namespace rpp
16{
21{
22public:
24 : m_sub{sub} {}
25
27
28 subscription_guard& operator=(const subscription_guard& other)
29 {
30 m_sub.unsubscribe();
31 m_sub = other.m_sub;
32 return *this;
33 }
34
35 void reset(const subscription_base& other)
36 {
37 m_sub.unsubscribe();
38 m_sub = other;
39 }
40
42 {
43 m_sub.unsubscribe();
44 }
45
46 const subscription_base* operator->() const { return &m_sub; }
47 const subscription_base& operator*() const { return m_sub; }
48private:
50};
51} // namespace rpp
Base subscription implementation used as base class/interface and core implementation for derrived su...
Definition: subscription_base.hpp:25
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