VLink  2.0.0
A high-performance communication middleware
vlink::CancellationSource类 参考final

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

#include <cancellation.h>

vlink::CancellationSource 的协作图:

Public 成员函数

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

详细描述

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.

构造及析构函数说明

◆ CancellationSource()

vlink::CancellationSource::CancellationSource ( )

Constructs an uncancelled source with no subscribed callbacks.

成员函数说明

◆ is_cancellation_requested()

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

Returns true once request_cancel has succeeded on this source.

返回
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.

返回
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.

返回
Valid CancellationToken sharing the source's state.

该类的文档由以下文件生成: