pub struct ServerHandle { /* private fields */ }Expand description
A handle to a server started by Server::run() or Server::run_ephemeral().
Dropping this handle without calling shutdown() leaves the server running in the
background for the life of the process — the same behavior run() always had before
this handle existed. Call shutdown() to stop accepting new connections and wait for
already-accepted connections to finish before returning.
Implementations§
Source§impl ServerHandle
impl ServerHandle
Sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Stop accepting new connections and wait up to DEFAULT_SHUTDOWN_DRAIN_TIMEOUT
(5s) for in-flight connections to finish on their own. Equivalent to
shutdown_with_timeout(DEFAULT_SHUTDOWN_DRAIN_TIMEOUT) — see that method for what
happens to connections still open once the grace period elapses.
Sourcepub async fn shutdown_with_timeout(self, drain_timeout: Duration)
pub async fn shutdown_with_timeout(self, drain_timeout: Duration)
Stop accepting new connections and wait up to drain_timeout for in-flight
connections to finish on their own.
Connections still open once drain_timeout elapses are aborted rather than
waited on further: dropping the accept task drops its JoinSet, which aborts
every task still tracked in it (see tokio::task::JoinSet’s own drop behavior) —
which in turn drops each connection’s socket, closing it. This is what bounds
shutdown when a connection has no natural end of its own (the live-reload SSE
stream is the motivating case: it stays open until a watched file changes, which
may never happen before the process needs to exit).
Auto Trait Implementations§
impl !RefUnwindSafe for ServerHandle
impl !UnwindSafe for ServerHandle
impl Freeze for ServerHandle
impl Send for ServerHandle
impl Sync for ServerHandle
impl Unpin for ServerHandle
impl UnsafeUnpin for ServerHandle
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more