Observable Reference
Generic observable objects for C++
Public Member Functions | List of all members
observable::shared_subscription Class Referencefinal

Description

Unsubscribe the associated observer when the last instance of the class is destroyed.

Note
All methods of this class can be safely called in parallel, from multiple threads.

Public Member Functions

 shared_subscription (infinite_subscription &&subscription)
 Create a shared subscription from a temporary infinite subscription. More...
 
 shared_subscription () noexcept=default
 Create an empty shared subscription. More...
 
void unsubscribe ()
 Unsubscribe the associated observer from receiving notifications. More...
 
 operator bool () const noexcept
 Return true if the subscription is not empty. More...
 
 shared_subscription (shared_subscription const &)=default
 This class is not copy-constructible. More...
 
auto operator= (shared_subscription const &) -> shared_subscription &=default
 This class is not copy-assignable. More...
 
 shared_subscription (shared_subscription &&)=default
 This class is move-constructible. More...
 
auto operator= (shared_subscription &&) -> shared_subscription &=default
 This class is move-assignable. More...
 

Constructor & Destructor Documentation

◆ shared_subscription() [1/4]

observable::shared_subscription::shared_subscription ( infinite_subscription &&  subscription)
inlineexplicit

Create a shared subscription from a temporary infinite subscription.

Parameters
subscriptionAn infinite subscription that will be converted to a shared subscription.
Note
The unique subscription will be released.

◆ shared_subscription() [2/4]

observable::shared_subscription::shared_subscription ( )
defaultnoexcept

Create an empty shared subscription.

Calling unsubscribe on an empty shared subscription will have no effect.

◆ shared_subscription() [3/4]

observable::shared_subscription::shared_subscription ( shared_subscription const &  )
default

This class is not copy-constructible.

◆ shared_subscription() [4/4]

observable::shared_subscription::shared_subscription ( shared_subscription &&  )
default

This class is move-constructible.

Member Function Documentation

◆ unsubscribe()

void observable::shared_subscription::unsubscribe ( )
inline

Unsubscribe the associated observer from receiving notifications.

Only the first call of this method will have an effect.

◆ operator bool()

observable::shared_subscription::operator bool ( ) const
inlineexplicitnoexcept

Return true if the subscription is not empty.

◆ operator=() [1/2]

auto observable::shared_subscription::operator= ( shared_subscription const &  ) -> shared_subscription &=default
default

This class is not copy-assignable.

◆ operator=() [2/2]

auto observable::shared_subscription::operator= ( shared_subscription &&  ) -> shared_subscription &=default
default

This class is move-assignable.