ShutdownToken

Struct ShutdownToken 

Source
pub struct ShutdownToken { /* private fields */ }
Expand description

A wrapped CancellationToken that is used for signalling and listening for cancellation requests.

Implementations§

Source§

impl ShutdownToken

Source

pub fn send_status_msg(&self, status: SentStatus)

👎Deprecated

A drop in no-op replacement for send_status_msg for easier migration from TaskClient.

Source

pub fn new() -> Self

Creates a new ShutdownToken in the non-cancelled state.

Source

pub fn new_from_tokio_token(cancellation_token: CancellationToken) -> Self

Creates a new ShutdownToken given a tokio CancellationToken.

Source

pub fn inner(&self) -> &CancellationToken

Gets reference to the underlying CancellationToken.

Source

pub fn to_cancellation_token(&self) -> CancellationToken

Get an owned CancellationToken for public API use. This is useful when you need to expose cancellation to SDK users without exposing the internal ShutdownToken type.

Source

pub fn child_token(&self) -> ShutdownToken

Creates a ShutdownToken which will get cancelled whenever the current token gets cancelled. Unlike a cloned ShutdownToken, cancelling a child token does not cancel the parent token.

If the current token is already cancelled, the child token will get returned in cancelled state.

Source

pub fn cancel(&self)

Cancel the underlying CancellationToken and all child tokens which had been derived from it.

This will wake up all tasks which are waiting for cancellation.

Source

pub fn is_cancelled(&self) -> bool

Returns true if the underlying CancellationToken is cancelled.

Source

pub fn cancelled(&self) -> WaitForCancellationFuture<'_>

Returns a Future that gets fulfilled when cancellation is requested.

The future will complete immediately if the token is already cancelled when this method is called.

§Cancel safety

This method is cancel safe.

Source

pub fn cancelled_owned(self) -> WaitForCancellationFutureOwned

Returns a Future that gets fulfilled when cancellation is requested.

The future will complete immediately if the token is already cancelled when this method is called.

The function takes self by value and returns a future that owns the token.

§Cancel safety

This method is cancel safe.

Source

pub fn drop_guard(self) -> ShutdownDropGuard

Creates a ShutdownDropGuard for this token.

Returned guard will cancel this token (and all its children) on drop unless disarmed.

Source

pub async fn run_until_cancelled<F>(&self, fut: F) -> Option<F::Output>
where F: Future,

Runs a future to completion and returns its result wrapped inside an Option unless the ShutdownToken is cancelled. In that case the function returns None and the future gets dropped.

§Cancel safety

This method is only cancel safe if fut is cancel safe.

Source

pub async fn run_until_cancelled_owned<F>(self, fut: F) -> Option<F::Output>
where F: Future,

Runs a future to completion and returns its result wrapped inside an Option unless the ShutdownToken is cancelled. In that case the function returns None and the future gets dropped.

The function takes self by value and returns a future that owns the token.

§Cancel safety

This method is only cancel safe if fut is cancel safe.

Trait Implementations§

Source§

impl Clone for ShutdownToken

Source§

fn clone(&self) -> ShutdownToken

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShutdownToken

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShutdownToken

Source§

fn default() -> ShutdownToken

Returns the “default value” for a type. Read more
Source§

impl From<CancellationToken> for ShutdownToken

Source§

fn from(inner: CancellationToken) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more