EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
eduart::subscription::Subscription Class Reference

Move-only RAII wrapper that pairs a SubscriberToken with an unsubscribe callable. Destroying a Subscription automatically cancels it. More...

#include <Subscription.hpp>

Public Member Functions

 Subscription () noexcept=default
 Default-construct an inactive Subscription.
 Subscription (SubscriberToken token, std::function< void()> unsubscribe)
 Construct from a token and an unsubscribe callable.
 Subscription (Subscription &&other) noexcept
 Move constructor.
Subscriptionoperator= (Subscription &&other) noexcept
 Move assignment operator.
 Subscription (const Subscription &)=delete
Subscriptionoperator= (const Subscription &)=delete
 ~Subscription ()
 Destructor — automatically cancels an active subscription.
void cancel () noexcept
 Cancel the subscription. Safe to call multiple times (idempotent).
bool isActive () const noexcept
 Check whether this subscription is still active.
SubscriberToken token () const noexcept
 Access the underlying token (e.g. for logging or debugging).

Detailed Description

Move-only RAII wrapper that pairs a SubscriberToken with an unsubscribe callable. Destroying a Subscription automatically cancels it.

Observables (MeasurementManager, Logger, …) return a Subscription from their subscribe methods. The holder can call cancel() explicitly or simply let the Subscription go out of scope.

Constructor & Destructor Documentation

◆ Subscription()

eduart::subscription::Subscription::Subscription ( SubscriberToken token,
std::function< void()> unsubscribe )
inline

Construct from a token and an unsubscribe callable.

Parameters
[in]tokenThe token identifying the subscription.
[in]unsubscribeCallable that removes the subscription from the observable.

Member Function Documentation

◆ isActive()

bool eduart::subscription::Subscription::isActive ( ) const
inlinenoexcept

Check whether this subscription is still active.

Returns
true if the subscription has not been cancelled.

◆ token()

SubscriberToken eduart::subscription::Subscription::token ( ) const
inlinenoexcept

Access the underlying token (e.g. for logging or debugging).

Returns
The SubscriberToken associated with this subscription.

The documentation for this class was generated from the following file: