pub struct ShutdownToken { /* private fields */ }Expand description
A wrapped CancellationToken that is used for signalling and listening for cancellation requests.
Implementations§
Source§impl ShutdownToken
impl ShutdownToken
Sourcepub fn send_status_msg(&self, status: SentStatus)
👎Deprecated
pub fn send_status_msg(&self, status: SentStatus)
A drop in no-op replacement for send_status_msg for easier migration from TaskClient.
Sourcepub fn new_from_tokio_token(cancellation_token: CancellationToken) -> Self
pub fn new_from_tokio_token(cancellation_token: CancellationToken) -> Self
Creates a new ShutdownToken given a tokio CancellationToken.
Sourcepub fn inner(&self) -> &CancellationToken
pub fn inner(&self) -> &CancellationToken
Gets reference to the underlying CancellationToken.
Sourcepub fn to_cancellation_token(&self) -> CancellationToken
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.
Sourcepub fn child_token(&self) -> ShutdownToken
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.
Sourcepub fn cancel(&self)
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.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the underlying CancellationToken is cancelled.
Sourcepub fn cancelled(&self) -> WaitForCancellationFuture<'_>
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.
Sourcepub fn cancelled_owned(self) -> WaitForCancellationFutureOwned
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.
Sourcepub fn drop_guard(self) -> ShutdownDropGuard
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.
Sourcepub async fn run_until_cancelled<F>(&self, fut: F) -> Option<F::Output>where
F: Future,
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.
Sourcepub async fn run_until_cancelled_owned<F>(self, fut: F) -> Option<F::Output>where
F: Future,
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
impl Clone for ShutdownToken
Source§fn clone(&self) -> ShutdownToken
fn clone(&self) -> ShutdownToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more