Struct salvo_core::server::ServerHandle
source · pub struct ServerHandle { /* private fields */ }
Available on crate feature
server
only.Expand description
Server handle is used to stop server.
Implementations§
source§impl ServerHandle
impl ServerHandle
sourcepub fn stop_forcible(&self)
pub fn stop_forcible(&self)
Force stop server.
Call this function will stop server immediately.
sourcepub fn stop_graceful(&self, timeout: impl Into<Option<Duration>>)
pub fn stop_graceful(&self, timeout: impl Into<Option<Duration>>)
Graceful stop server.
Call this function will stop server after all connections are closed, allowing it to finish processing any ongoing requests before terminating. It ensures that all connections are closed properly and any resources are released.
You can specify a timeout to force stop server.
If timeout
is None
, it will wait util all connections are closed.
This function gracefully stop the server, allowing it to finish processing any ongoing requests before terminating. It ensures that all connections are closed properly and any resources are released.
§Examples
use salvo_core::prelude::*;
#[tokio::main]
async fn main() {
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
let server = Server::new(acceptor);
let handle = server.handle();
// Graceful shutdown the server
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
handle.stop_graceful(None);
});
server.serve(Router::new()).await;
}
Trait Implementations§
source§impl Clone for ServerHandle
impl Clone for ServerHandle
source§fn clone(&self) -> ServerHandle
fn clone(&self) -> ServerHandle
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ServerHandle
impl !RefUnwindSafe for ServerHandle
impl Send for ServerHandle
impl Sync for ServerHandle
impl Unpin for ServerHandle
impl !UnwindSafe for ServerHandle
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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