ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
callback_subscription.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#include <rpp/subscriptions/details/subscription_state.hpp>
15
16#include <concepts>
17#include <utility>
18
19namespace rpp
20{
25{
26public:
27 template<std::invocable Fn>
29 : subscription_base{std::make_shared<state<std::decay_t<Fn>>>(std::forward<Fn>(fn))} { }
30
31private:
32 template<std::invocable Fn>
33 class state final : public details::subscription_state
34 {
35 public:
36 state(const Fn& fn)
37 : m_fn{fn} {}
38
39 state(Fn&& fn)
40 : m_fn{std::move(fn)} {}
41
42 protected:
43 void on_unsubscribe() override
44 {
45 m_fn();
46 }
47
48 private:
49 Fn m_fn{};
50 };
51};
52} // namespace rpp
Subscription which invoke callbable during unsubscribe.
Definition: callback_subscription.hpp:25
Base implementation of subscription state used under-hood for rpp::subscription_base and its childs.
Definition: subscription_state.hpp:22
Base subscription implementation used as base class/interface and core implementation for derrived su...
Definition: subscription_base.hpp:25