Struct tokio_graceful::Shutdown
source · pub struct Shutdown { /* private fields */ }
Expand description
The Shutdown
struct is the main entry point to the shutdown system.
It is created by calling Shutdown::new
, which takes a Future
that
will be awaited on when shutdown is requested. Most users will want to
create a Shutdown
with Shutdown::default
, which uses the default
signal handler to trigger shutdown. See default_signal
for more info.
See the README for more info on how to use this crate.
Implementations§
source§impl Shutdown
impl Shutdown
sourcepub fn guard(&self) -> ShutdownGuard
pub fn guard(&self) -> ShutdownGuard
Returns a ShutdownGuard
which primary use
is to prevent the Shutdown
from shutting down.
The creation of a ShutdownGuard
is lockfree.
sourcepub fn guard_weak(&self) -> WeakShutdownGuard
pub fn guard_weak(&self) -> WeakShutdownGuard
Returns a WeakShutdownGuard
which in contrast to
ShutdownGuard
does not prevent the Shutdown
from shutting down.
Instead it is used to wait for
“shutdown signal” to be triggered or to create
a ShutdownGuard
which prevents the Shutdown
once and only once it is needed.
The creation of a WeakShutdownGuard
is lockfree.
sourcepub fn spawn_task<T>(&self, task: T) -> JoinHandle<T::Output>where
T: Future + Send + 'static,
T::Output: Send + 'static,
pub fn spawn_task<T>(&self, task: T) -> JoinHandle<T::Output>where T: Future + Send + 'static, T::Output: Send + 'static,
Returns a Tokio JoinHandle
that can be awaited on
to wait for the spawned task to complete. See
tokio::spawn
for more information.
sourcepub fn spawn_task_fn<T, F>(&self, task: F) -> JoinHandle<T::Output>where
T: Future + Send + 'static,
T::Output: Send + 'static,
F: FnOnce(ShutdownGuard) -> T + Send + 'static,
pub fn spawn_task_fn<T, F>(&self, task: F) -> JoinHandle<T::Output>where T: Future + Send + 'static, T::Output: Send + 'static, F: FnOnce(ShutdownGuard) -> T + Send + 'static,
Returns a Tokio JoinHandle
that can be awaited on
to wait for the spawned task (fn) to complete. See
tokio::spawn
for more information.
sourcepub async fn shutdown(self) -> Duration
pub async fn shutdown(self) -> Duration
Returns a future that completes once the Shutdown
has been triggered
and all ShutdownGuard
s have been dropped.
The resolved Duration
is the time it took for the Shutdown
to
to wait for all ShutdownGuard
s to be dropped.
You can use Shutdown::shutdown_with_limit
to limit the time the
Shutdown
waits for all ShutdownGuard
s to be dropped.
Panics
This method can panic if the internal mutex is poisoned.
sourcepub async fn shutdown_with_limit(
self,
limit: Duration
) -> Result<Duration, TimeoutError>
pub async fn shutdown_with_limit( self, limit: Duration ) -> Result<Duration, TimeoutError>
Returns a future that completes once the Shutdown
has been triggered
and all ShutdownGuard
s have been dropped or the given Duration
has elapsed.
The resolved Duration
is the time it took for the Shutdown
to
to wait for all ShutdownGuard
s to be dropped.
You can use Shutdown::shutdown
to wait for all ShutdownGuard
s
to be dropped without a time limit.
Panics
This method can panic if the internal mutex is poisoned.