Struct async_shutdown::Shutdown [−][src]
pub struct Shutdown { /* fields omitted */ }
Expand description
Shutdown manager for asynchronous tasks and futures.
The shutdown manager serves two separate but related purposes:
- To signal futures to shutdown or forcibly cancel them (by dropping them).
- To wait for futures to perform their clean-up after a shutdown was triggered.
The shutdown manager can be cloned and shared with multiple tasks. Each clone uses the same internal state.
Implementations
Check if the shutdown has been started.
Check if the shutdown has been completed.
pub fn wait_shutdown_triggered(&self) -> ShutdownSignalⓘNotable traits for ShutdownSignalimpl Future for ShutdownSignal type Output = ();
pub fn wait_shutdown_triggered(&self) -> ShutdownSignalⓘNotable traits for ShutdownSignalimpl Future for ShutdownSignal type Output = ();
impl Future for ShutdownSignal type Output = ();
Asynchronously wait for a shutdown to be triggered.
This returns a future that completes when a shutdown is triggered. The future can be cloned and sent to other threads or tasks freely.
If a shutdown is already triggered, the returned future immediately resolves.
You can also use ShutdownSignal::wrap_cancel()
of the returned object
to automatically cancel a future when the shutdown signal is received.
This is identical to Self::wrap_cancel()
, but can be done if you only have a ShutdownSignal
.
pub fn wait_shutdown_complete(&self) -> ShutdownCompleteⓘNotable traits for ShutdownCompleteimpl Future for ShutdownComplete type Output = ();
pub fn wait_shutdown_complete(&self) -> ShutdownCompleteⓘNotable traits for ShutdownCompleteimpl Future for ShutdownComplete type Output = ();
impl Future for ShutdownComplete type Output = ();
Asynchronously wait for the shutdown to complete.
This returns a future that completes when the shutdown is complete. The future can be cloned and sent to other threads or tasks freely.
The shutdown is complete when all DelayShutdownToken
are dropped
and all WrapWait
futures have completed.
Start the shutdown.
This will complete all ShutdownSignal
and WrapCancel
futures associated with this shutdown manager.
The shutdown will not complete until all registered futures complete.
If the shutdown was already started, this function is a no-op.
pub fn wrap_cancel<F: Future>(&self, future: F) -> WrapCancel<F>ⓘNotable traits for WrapCancel<F>impl<F: Future> Future for WrapCancel<F> type Output = Option<F::Output>;
pub fn wrap_cancel<F: Future>(&self, future: F) -> WrapCancel<F>ⓘNotable traits for WrapCancel<F>impl<F: Future> Future for WrapCancel<F> type Output = Option<F::Output>;
impl<F: Future> Future for WrapCancel<F> type Output = Option<F::Output>;
Wrap a future so that it is cancelled when a shutdown is triggered.
The returned future completes with None
when a shutdown is triggered,
and with Some(x)
when the wrapped future completes.
The wrapped future is dropped when the shutdown starts before the future completed. If the wrapped future completes before the shutdown signal arrives, it is not dropped.
Wrap a future to cause a shutdown when it completes or is dropped.
Wrap a future to delay shutdown completion until it completes or is dropped.
The returned future transparently completes with the value of the wrapped future. However, the shutdown will not be considered complete until the future completes or is dropped.
If the shutdown has already completed, this function returns an error.
Get a token to delay shutdown completion.
The manager keeps track of all the tokens it hands out. The tokens can be cloned and sent to different threads and tasks. All tokens (including the clones) must be dropped before the shutdown is considered to be complete.
If the shutdown has already completed, this function returns an error.
If you want to delay the shutdown until a future completes,
consider using Self::wrap_wait()
instead.
Get a token that represents a vital task or future.
When a VitalToken
is dropped, the shutdown is triggered automatically.
This applies to any token.
If you clone a token five times and drop one a shutdown is triggered,
even though four tokens still exist.
You can also use Self::wrap_vital()
to wrap a future so that a shutdown is triggered
when the future completes or if it is dropped.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Shutdown
impl UnwindSafe for Shutdown
Blanket Implementations
Mutably borrows from an owned value. Read more