pub struct Swansong { /* private fields */ }Expand description
Implementationsยง
Sourceยงimpl Swansong
impl Swansong
Sourcepub fn shut_down(&self) -> ShutdownCompletion
pub fn shut_down(&self) -> ShutdownCompletion
Initiate graceful shutdown.
This will gracefully stop any associated Interrupts.
This returns a ShutdownCompletion type, which can be blocked on with
ShutdownCompletion::block or awaited as a Future.
Sourcepub fn block_on_shutdown_completion(self)
pub fn block_on_shutdown_completion(self)
Blocks the current thread until graceful shutdown is complete
Do not use this in async contexts. Instead, await the Swansong
Sourcepub fn state(&self) -> ShutdownState
pub fn state(&self) -> ShutdownState
Determine if this Swansong is running, shutting down, or complete.
Sourcepub fn interrupt<T>(&self, wrapped_type: T) -> Interrupt<T>
pub fn interrupt<T>(&self, wrapped_type: T) -> Interrupt<T>
Wrap any type with an Interrupt, allowing it to cancel or seal on shutdown.
Interrupt<T> has custom implementations of Future,
Stream, [AsyncRead][futures_io::AsyncRead],
[AsyncWrite][futures_io::AsyncWrite], [AsyncBufRead][futures_io::AsyncBufRead], and
Iterator. See further documentation for the behaviors for each of these types at
Interrupt.
Each of the trait implementations will behave normally with a small overhead to check
shutdown state until shutdown has been initiated with Swansong::shut_down. When shutdown
has been initiated, any type inside of an associated Interrupt will be
interrupted/canceled/sealed at an appropriate time.
Sourcepub fn guard(&self) -> Guard
pub fn guard(&self) -> Guard
Returns a new Guard, which forstalls shutdown until it is dropped.
Sourcepub fn guard_count(&self) -> usize
pub fn guard_count(&self) -> usize
The current number of outstanding Guards.
Sourcepub fn child(&self) -> Swansong
pub fn child(&self) -> Swansong
Create a child Swansong linked to this parent.
The child can be independently shut down without affecting the parent. However, when
the parent is shut down, the child will also be shut down. The parentโs shutdown will
not be considered complete until the child Swansong and any associated
ShutdownCompletions are dropped.
This supports multi-level hierarchies: a child can itself have children, forming a tree. Shutdown propagates downward through the entire tree.
ยงPerformance
Creating a child has O(n) cost where n is the number of live children, due to cleanup of stale internal references. This is suitable for most use cases but may not be ideal for very high-frequency child creation with many concurrent children.
ยงExample: HTTP/3 server
let server = Swansong::new();
// Each connection gets its own child swansong
let connection = server.child();
// Connection can be shut down independently (e.g., on GOAWAY)
connection.shut_down();
// Or the entire server can shut down, which also stops all connections
// server.shut_down().await;Sourcepub fn guarded<T>(&self, wrapped_type: T) -> Guarded<T>
pub fn guarded<T>(&self, wrapped_type: T) -> Guarded<T>
Attach a guard to the provided type, delaying shutdown until it drops.
This function returns a Guarded wrapper type provides transparent implementations of
various traits like Future and Stream, as
well as Derefing to the wrapped type. This is identical to moving a Guard into the
wrapped type, but sometimes itโs easier to compose the guard around a named future than to
move the guard into the future. See Guarded for more information about trait
implementations on Guarded
Trait Implementationsยง
Sourceยงimpl AsRef<Swansong> for ServerConfig
impl AsRef<Swansong> for ServerConfig
Sourceยงimpl IntoFuture for Swansong
impl IntoFuture for Swansong
Sourceยงtype IntoFuture = ShutdownCompletion
type IntoFuture = ShutdownCompletion
Sourceยงfn into_future(self) -> <Swansong as IntoFuture>::IntoFuture
fn into_future(self) -> <Swansong as IntoFuture>::IntoFuture
impl Eq for Swansong
Auto Trait Implementationsยง
impl Freeze for Swansong
impl RefUnwindSafe for Swansong
impl Send for Swansong
impl Sync for Swansong
impl Unpin for Swansong
impl UnsafeUnpin for Swansong
impl UnwindSafe for Swansong
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.