pub struct ServeWithGracefulShutdown<L, M, S, F, B> { /* private fields */ }Expand description
A server future with graceful shutdown enabled.
This type is created by calling Serve::with_graceful_shutdown. It implements
IntoFuture, so you can directly .await it.
When the shutdown signal completes, the server will:
- Stop accepting new connections
- Wait for all in-flight requests to complete (or until timeout if configured)
- Return once all connections are closed
Configure the shutdown timeout with with_shutdown_timeout.
Created by Serve::with_graceful_shutdown.
Implementations§
Source§impl<L: Listener, M, S, F, B> ServeWithGracefulShutdown<L, M, S, F, B>
impl<L: Listener, M, S, F, B> ServeWithGracefulShutdown<L, M, S, F, B>
Sourcepub fn with_shutdown_timeout(self, timeout: Duration) -> Self
pub fn with_shutdown_timeout(self, timeout: Duration) -> Self
Set a timeout for graceful shutdown.
If the timeout expires before all connections complete, a warning is logged and the server returns successfully. Note that this does not forcibly terminate connections - it only stops waiting for them.
§Example
ⓘ
use std::time::Duration;
serve(listener, app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.with_shutdown_timeout(Duration::from_secs(30))
.await?; // Returns Ok(()) even if timeout expiresSourcepub fn local_addr(&self) -> Result<L::Addr>
pub fn local_addr(&self) -> Result<L::Addr>
Returns the local address this server is bound to.
Trait Implementations§
Source§impl<L, M, S, F, B> Debug for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Debug for ServeWithGracefulShutdown<L, M, S, F, B>
Source§impl<L, M, S, F, B> IntoFuture for ServeWithGracefulShutdown<L, M, S, F, B>where
L: Listener,
L::Addr: Debug,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
S: Service<Request<Incoming>, Response = Response<B>, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a, L>>>::Future: Send,
F: Future<Output = ()> + Send + 'static,
impl<L, M, S, F, B> IntoFuture for ServeWithGracefulShutdown<L, M, S, F, B>where
L: Listener,
L::Addr: Debug,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
S: Service<Request<Incoming>, Response = Response<B>, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a, L>>>::Future: Send,
F: Future<Output = ()> + Send + 'static,
Source§type IntoFuture = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
type IntoFuture = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl<L, M, S, F, B> Freeze for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> !RefUnwindSafe for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Send for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Sync for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Unpin for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> !UnwindSafe for ServeWithGracefulShutdown<L, M, S, F, B>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.