FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    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).

    View source

    Members

    new

    fn new() -> Self
    

    A token that can be canceled, by itself and its clones (a new CancellationTokenSource and its token in one).

    Source

    none

    const fn none() -> Self
    

    A token that can never be canceled.

    Source

    can_be_cancelled

    fn can_be_cancelled(self: &Self) -> bool
    

    Whether this token is capable of being in the canceled state.

    Source

    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

    Source

    is_cancelled

    fn is_cancelled(self: &Self) -> bool
    

    Whether the token is canceled.

    Source

    is_cancellation_requested

    fn is_cancellation_requested(self: &Self) -> bool
    

    Whether the token is canceled.

    Deprecated since 0.5.0. use is_cancelled

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    drop_guard

    fn drop_guard(self: Self) -> DropGuard
    

    A guard that cancels the token when it is dropped, unless it is disarmed.

    Source

    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.

    Source

    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

    Source

    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

    Source

    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.

    Source

    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

    Source

    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

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • Borrow<T>
    • BorrowMut<T>
    • CloneToUninit
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToOwned
    • Clone
    • Default
    • Debug
    • From<CancellationTokenSource>

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.