pavex/server/shutdown_mode.rs
1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4#[non_exhaustive]
5/// Determine how a running [`Server`](super::Server) should shut down.
6///
7/// Use [`ServerHandle::shutdown`](super::ServerHandle::shutdown) to initiate the shutdown sequence.
8pub enum ShutdownMode {
9 /// Wait for each worker thread to finish handling its open connections before shutting down.
10 Graceful {
11 /// As much as we want to be graceful, we can't wait forever!
12 /// Any connection that has not been handled within the specified `timeout` will be dropped.
13 timeout: Duration,
14 },
15 /// Shut down immediately, dropping all open connections abruptly.
16 Forced,
17}
18
19impl ShutdownMode {
20 /// Returns `true` if you are asking for a graceful shutdown.
21 pub fn is_graceful(&self) -> bool {
22 matches!(self, Self::Graceful { .. })
23 }
24
25 /// Returns `true` if you are asking for a forced shutdown.
26 pub fn is_forced(&self) -> bool {
27 matches!(self, Self::Forced)
28 }
29}