CancellationToken
struct · ferroui-system · v0.5.0
struct CancellationToken
Propagates notification that operations should be canceled.
The clones of a token share its state: any of them cancels it, and all of them see it.
Default is none, a token that can never be canceled (the default of .NET's
CancellationToken; tokio_util's default is a new token).
Members
newnonecan_be_cancelledcan_be_canceledis_cancelledis_cancellation_requestedcancelchild_tokencancelleddrop_guardregisterregister_guardedregister_handleregister_localregister_local_guardedregister_local_handle
new
fn new() -> Self
A token that can be canceled, by itself and its clones (a new CancellationTokenSource
and its token in one).
none
const fn none() -> Self
A token that can never be canceled.
can_be_cancelled
fn can_be_cancelled(self: &Self) -> bool
Whether this token is capable of being in the canceled state.
can_be_canceled
fn can_be_canceled(self: &Self) -> bool
Whether this token is capable of being in the canceled state.
Deprecated since 0.5.0. use
can_be_cancelled
is_cancelled
fn is_cancelled(self: &Self) -> bool
Whether the token is canceled.
is_cancellation_requested
fn is_cancellation_requested(self: &Self) -> bool
Whether the token is canceled.
Deprecated since 0.5.0. use
is_cancelled
cancel
fn cancel(self: &Self)
Cancels the token and its children, and runs the registered callbacks and wakes the futures awaiting it, on the calling thread, in the order of registration. Subsequent calls, and calls on a token that cannot be canceled, do nothing.
child_token
fn child_token(self: &Self) -> CancellationToken
A token canceled when this one is, which can also be canceled on its own without canceling this one. It is canceled at once when this one already is; a child of a token that cannot be canceled is a new token. The children of a token are canceled in its pass of the callbacks, in the order they were made among them; a child whose clones are all dropped is removed from its parent.
cancelled
fn cancelled(self: &Self) -> WaitForCancellation
A future that completes when the token is canceled; at once when it already is, never for
a token that cannot be canceled. It owns a clone of the token, is Send, and is woken on
the cancelling thread, in the pass of the callbacks.
drop_guard
fn drop_guard(self: Self) -> DropGuard
A guard that cancels the token when it is dropped, unless it is disarmed.
register
fn register(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationGuard
Registers a callback that runs, on the cancelling thread, when the token is canceled; at
once on the calling thread when it already is. Dropping the guard removes it
(CancellationGuard::detach keeps it). The callback never runs for a token that cannot
be canceled.
register_guarded
fn register_guarded(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationGuard
The former name of register.
Deprecated since 0.5.0. use
register, which gives the same guard
register_handle
fn register_handle(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationTokenRegistration
Registers a callback that runs when the token is canceled. When the token is already canceled the callback runs immediately.
Dropping the returned registration keeps the callback (the IDisposable contract).
Deprecated since 0.5.0. use
register, whose guard removes the callback when it is dropped;detach()keeps it
register_local
fn register_local(self: &Self, callback: impl FnOnce() -> () + 'static) -> CancellationGuard
Registers a callback that runs on the current thread when the token is canceled: at once
when it is canceled on this thread, or already canceled; through the schedule of this thread
(crate::task::set_thread_schedule; a dispatcher, in a job at its default priority), or
its queue of run_pending, when it is
canceled on another thread. The callback need not be Send; the guard is: dropped on
another thread, it removes the registration at once and the callback is dropped on its own
thread, the next time that thread runs its queue. CancellationGuard::detach keeps it.
register_local_guarded
fn register_local_guarded(self: &Self, callback: impl FnOnce() -> () + 'static) -> CancellationGuard
The former name of register_local.
Deprecated since 0.5.0. use
register_local, which gives the same guard
register_local_handle
fn register_local_handle(self: &Self, callback: impl FnOnce() -> () + 'static) -> LocalCancellationTokenRegistration
Registers a callback that runs on the current thread when the token is canceled, as
register_local does; dropping the returned registration keeps it.
Deprecated since 0.5.0. use
register_local, whose guard removes the callback when it is dropped;detach()keeps it
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedCloneDefaultDebugFrom<CancellationTokenSource>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.