pub struct Shutdown { /* private fields */ }Expand description
A cloneable handle used to request and observe server shutdown.
Every clone refers to the same underlying signal. The server stops accepting connections once it is triggered, background tasks receive it, and long-lived handlers (WebSockets, streaming responses) should watch it to finish cleanly:
use kerniq_runtime::Shutdown;
let shutdown = Shutdown::new();
let watcher = shutdown.clone();
let task = tokio::spawn(async move {
watcher.wait().await;
"stopped"
});
shutdown.trigger();
assert_eq!(task.await.unwrap(), "stopped");Implementations§
Source§impl Shutdown
impl Shutdown
Sourcepub fn is_triggered(&self) -> bool
pub fn is_triggered(&self) -> bool
Whether shutdown has been requested.
Sourcepub fn wait_owned(&self) -> impl Future<Output = ()> + Send + 'static
pub fn wait_owned(&self) -> impl Future<Output = ()> + Send + 'static
An owned future that completes on shutdown (useful for select! in
'static contexts).
Sourcepub fn token(&self) -> &CancellationToken
pub fn token(&self) -> &CancellationToken
The underlying Tokio cancellation token, for interoperability.
Trait Implementations§
Source§impl From<CancellationToken> for Shutdown
impl From<CancellationToken> for Shutdown
Source§fn from(token: CancellationToken) -> Self
fn from(token: CancellationToken) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Forget for Shutdown
impl Freeze for Shutdown
impl RefUnwindSafe for Shutdown
impl Send for Shutdown
impl Sync for Shutdown
impl Unpin for Shutdown
impl UnsafeUnpin for Shutdown
impl UnwindSafe for Shutdown
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