|
VLink
2.0.0
A high-performance communication middleware
|
Lightweight observer of a CancellationSource shared across worker threads.
更多...
#include <cancellation.h>
Public 成员函数 | |
| CancellationToken () noexcept | |
| Constructs an invalid token not bound to any source. 更多... | |
| bool | valid () const noexcept |
| Reports whether the token observes a live cancellation source. 更多... | |
| bool | is_cancellation_requested () const noexcept |
Returns true once the bound source has been cancelled. 更多... | |
| CancellationRegistration | register_callback (MoveFunction< void()> &&callback) const |
| Subscribes a one-shot callback to fire when the source is cancelled. 更多... | |
| void | throw_if_cancellation_requested () const |
Throws vlink::Exception::OperationCancelled when cancellation has been requested. 更多... | |
友元 | |
| class | CancellationSource |
Lightweight observer of a CancellationSource shared across worker threads.
Tokens are cheap to copy and safe to hand to any thread; many tokens may observe the same source concurrently. A default-constructed token is invalid – it never reports cancellation and never accepts callbacks. Workers typically poll is_cancellation_requested at safe points, call throw_if_cancellation_requested at structured points, or install a one-shot callback via register_callback.
|
noexcept |
Constructs an invalid token not bound to any source.
|
noexcept |
Returns true once the bound source has been cancelled.
true after the source's request_cancel has succeeded. | CancellationRegistration vlink::CancellationToken::register_callback | ( | MoveFunction< void()> && | callback | ) | const |
Subscribes a one-shot callback to fire when the source is cancelled.
When cancellation has not yet been requested the callback is stored in the source and fires once on the thread that later calls CancellationSource::request_cancel. When cancellation already happened the callback runs synchronously inside this call and the returned registration is empty. Exceptions escaping the callback are caught and logged via CLOG_E; they never propagate to the registering or cancelling thread.
| callback | Move-only nullary functor; an empty callback is silently ignored. |
| void vlink::CancellationToken::throw_if_cancellation_requested | ( | ) | const |
Throws vlink::Exception::OperationCancelled when cancellation has been requested.
|
noexcept |
Reports whether the token observes a live cancellation source.
true when the token was minted from a CancellationSource.
|
friend |