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: Box<dyn TaskStatusEvent>)
👎Deprecated
pub fn send_status_msg(&self, status: Box<dyn TaskStatusEvent>)
A drop in no-op replacement for send_status_msg for easier migration from TaskClient.
Sourcepub fn new() -> ShutdownToken
pub fn new() -> ShutdownToken
Creates a new ShutdownToken in the non-cancelled state.
Sourcepub fn new_from_tokio_token(
cancellation_token: CancellationToken,
) -> ShutdownToken
pub fn new_from_tokio_token( cancellation_token: CancellationToken, ) -> ShutdownToken
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 as Future>::Output>where
F: Future,
pub async fn run_until_cancelled<F>(
&self,
fut: F,
) -> Option<<F as Future>::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 as Future>::Output>where
F: Future,
pub async fn run_until_cancelled_owned<F>(
self,
fut: F,
) -> Option<<F as Future>::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 moreSource§impl Debug for ShutdownToken
impl Debug for ShutdownToken
Source§impl Default for ShutdownToken
impl Default for ShutdownToken
Source§fn default() -> ShutdownToken
fn default() -> ShutdownToken
Source§impl From<CancellationToken> for ShutdownToken
impl From<CancellationToken> for ShutdownToken
Source§fn from(inner: CancellationToken) -> ShutdownToken
fn from(inner: CancellationToken) -> ShutdownToken
Auto Trait Implementations§
impl Freeze for ShutdownToken
impl RefUnwindSafe for ShutdownToken
impl Send for ShutdownToken
impl Sync for ShutdownToken
impl Unpin for ShutdownToken
impl UnwindSafe for ShutdownToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Deprecatable for T
impl<T> Deprecatable for T
fn deprecate(self) -> Deprecated<Self>where
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OptionalSet for T
impl<T> OptionalSet for T
Source§fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
Some), the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_validated_optional<F, T, V, E>(
self,
f: F,
value: Option<T>,
validate: V,
) -> Result<Self, E>
fn with_validated_optional<F, T, V, E>( self, f: F, value: Option<T>, validate: V, ) -> Result<Self, E>
Some) it is validated and then the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the FromStr implementation and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.Source§fn with_optional_custom_env<F, T, G>(
self,
f: F,
val: Option<T>,
env_var: &str,
parser: G,
) -> Self
fn with_optional_custom_env<F, T, G>( self, f: F, val: Option<T>, env_var: &str, parser: G, ) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the provided parser and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.