VLink  2.0.0
A high-performance communication middleware
vlink::CancellationSource Class Referencefinal

Mutator that mints observer tokens and signals one-shot cancellation. More...

#include <cancellation.h>

Collaboration diagram for vlink::CancellationSource:

Public Member Functions

 CancellationSource ()
 Constructs an uncancelled source with no subscribed callbacks. More...
 
CancellationToken token () const noexcept
 Returns a fresh observer token bound to this source. More...
 
bool is_cancellation_requested () const noexcept
 Returns true once request_cancel has succeeded on this source. More...
 
bool request_cancel () const
 Performs the one-shot active -> cancelled transition and fires registered callbacks. More...
 

Detailed Description

Mutator that mints observer tokens and signals one-shot cancellation.

Holds a refcounted handle to the cancellation state; copies and moves share that state, so any copy can mint tokens or request cancellation against the same one-shot transition. token returns a cheap observer; request_cancel performs the transition exactly once and fires every subscribed callback.

Constructor & Destructor Documentation

◆ CancellationSource()

vlink::CancellationSource::CancellationSource ( )

Constructs an uncancelled source with no subscribed callbacks.

Member Function Documentation

◆ is_cancellation_requested()

bool vlink::CancellationSource::is_cancellation_requested ( ) const
noexcept

Returns true once request_cancel has succeeded on this source.

Returns
true after the one-shot transition has completed.

◆ request_cancel()

bool vlink::CancellationSource::request_cancel ( ) const

Performs the one-shot active -> cancelled transition and fires registered callbacks.

Acquires the internal state mutex, swaps the cancellation flag, releases the mutex, then runs every callback that was attached at the moment of the transition. Exceptions thrown by callbacks are caught and logged.

Returns
true when this call performed the transition; false when a previous call had already cancelled the source.

◆ token()

CancellationToken vlink::CancellationSource::token ( ) const
noexcept

Returns a fresh observer token bound to this source.

Returns
Valid CancellationToken sharing the source's state.

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