5#ifndef MOLYBDEN_SUBSCRIPTION_IMPL_HPP
6#define MOLYBDEN_SUBSCRIPTION_IMPL_HPP
13#include "molybden/base/subscription.hpp"
18class SubscriptionObserver {
20 virtual ~SubscriptionObserver() =
default;
22 virtual void onCanceled(int32_t
id){};
26class SubscriptionImpl :
public Subscription {
28 SubscriptionImpl(int32_t
id, std::function<
void(
const T& e)> observer);
30 void notify(
const T& event);
34 void setObserver(SubscriptionObserver* observer);
38 std::function<void(
const T& e)> event_observer_;
39 SubscriptionObserver* subscription_observer_;
43SubscriptionImpl<T>::SubscriptionImpl(int32_t
id,
44 std::function<
void(
const T&)> observer)
45 : id_(id), event_observer_(std::move(observer)) {}
48void SubscriptionImpl<T>::notify(
const T& event) {
49 if (event_observer_) {
50 event_observer_(event);
55void SubscriptionImpl<T>::cancel() {
57 if (subscription_observer_) {
58 subscription_observer_->onCanceled(id_);
63void SubscriptionImpl<T>::setObserver(SubscriptionObserver* observer) {
64 subscription_observer_ = observer;
virtual void cancel()=0
Cancels this subscription.