Struct async_shutdown::TriggerShutdownToken
source · pub struct TriggerShutdownToken<T: Clone> { /* private fields */ }
Expand description
Token that triggers a shutdown when it is dropped.
The token can be cloned and sent to different threads and tasks freely. If one of the cloned tokens is dropped, a shutdown is triggered. Even if the rest of the clones still exist.
Implementations§
source§impl<T: Clone> TriggerShutdownToken<T>
impl<T: Clone> TriggerShutdownToken<T>
sourcepub fn wrap_future<F: Future>(self, future: F) -> WrapTriggerShutdown<T, F> ⓘ
pub fn wrap_future<F: Future>(self, future: F) -> WrapTriggerShutdown<T, F> ⓘ
Wrap a future to trigger a shutdown when it completes or is dropped.
This consumes the token to avoid accidentally dropping the token after wrapping a future and instantly causing a shutdown.
If you need to keep the token around, you can clone it first:
let future = trigger_shutdown_token.clone().wrap_future(future);
sourcepub fn forget(self)
pub fn forget(self)
Drop the token without causing a shutdown.
This is equivalent to calling std::mem::forget()
on the token.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TriggerShutdownToken<T>
impl<T> RefUnwindSafe for TriggerShutdownToken<T>
impl<T> Send for TriggerShutdownToken<T>where
T: Send,
impl<T> Sync for TriggerShutdownToken<T>where
T: Send,
impl<T> Unpin for TriggerShutdownToken<T>
impl<T> UnwindSafe for TriggerShutdownToken<T>
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
Mutably borrows from an owned value. Read more