mirror of
https://github.com/fafhrd91/actix-web
synced 2025-05-19 07:23:17 +02:00
feat: add HttpServer::shutdown_signal (#3644)
This commit is contained in:
parent
f1b7cfb253
commit
6e902d1d5c
@ -1,6 +1,8 @@
|
||||
version: "0.2"
|
||||
words:
|
||||
- actix
|
||||
- addrs
|
||||
- httparse
|
||||
- msrv
|
||||
- rustup
|
||||
- zstd
|
||||
|
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -251,9 +251,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "actix-server"
|
||||
version = "2.5.1"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6398974fd4284f4768af07965701efbbb5fdc0616bff20cade1bb14b77675e24"
|
||||
checksum = "a65064ea4a457eaf07f2fba30b4c695bf43b721790e9530d26cb6f9019ff7502"
|
||||
dependencies = [
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
@ -397,6 +397,7 @@ dependencies = [
|
||||
"static_assertions",
|
||||
"time",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"url",
|
||||
"zstd",
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Add `HttpServer::shutdown_signal()` method.
|
||||
- Mark `HttpServer` as `#[must_use]`.
|
||||
- Update `brotli` dependency to `8`.
|
||||
|
||||
## 4.10.2
|
||||
|
@ -132,7 +132,7 @@ compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-for
|
||||
actix-codec = "0.5"
|
||||
actix-macros = { version = "0.2.3", optional = true }
|
||||
actix-rt = { version = "2.6", default-features = false }
|
||||
actix-server = "2"
|
||||
actix-server = "2.6"
|
||||
actix-service = "2"
|
||||
actix-utils = "3"
|
||||
actix-tls = { version = "3.4", default-features = false, optional = true }
|
||||
@ -188,6 +188,7 @@ static_assertions = "1"
|
||||
tls-openssl = { package = "openssl", version = "0.10.55" }
|
||||
tls-rustls = { package = "rustls", version = "0.23" }
|
||||
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] }
|
||||
tokio-util = "0.7"
|
||||
zstd = "0.13"
|
||||
|
||||
[lints]
|
||||
|
@ -1,6 +1,8 @@
|
||||
use std::{
|
||||
any::Any,
|
||||
cmp, fmt, io,
|
||||
cmp, fmt,
|
||||
future::Future,
|
||||
io,
|
||||
marker::PhantomData,
|
||||
net,
|
||||
sync::{Arc, Mutex},
|
||||
@ -64,6 +66,7 @@ struct Config {
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub struct HttpServer<F, I, S, B>
|
||||
where
|
||||
F: Fn() -> I + Send + Clone + 'static,
|
||||
@ -312,6 +315,37 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify shutdown signal from a future.
|
||||
///
|
||||
/// Using this method will prevent OS signal handlers being set up.
|
||||
///
|
||||
/// Typically, a `CancellationToken` will be used, but any future _can_ be.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use actix_web::{App, HttpServer};
|
||||
/// use tokio_util::sync::CancellationToken;
|
||||
///
|
||||
/// # #[actix_web::main]
|
||||
/// # async fn main() -> std::io::Result<()> {
|
||||
/// let stop_signal = CancellationToken::new();
|
||||
///
|
||||
/// HttpServer::new(move || App::new())
|
||||
/// .shutdown_signal(stop_signal.cancelled_owned())
|
||||
/// .bind(("127.0.0.1", 8080))?
|
||||
/// .run()
|
||||
/// .await
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn shutdown_signal<Fut>(mut self, shutdown_signal: Fut) -> Self
|
||||
where
|
||||
Fut: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
self.builder = self.builder.shutdown_signal(shutdown_signal);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets timeout for graceful worker shutdown of workers.
|
||||
///
|
||||
/// After receiving a stop signal, workers have this much time to finish serving requests.
|
||||
|
Loading…
x
Reference in New Issue
Block a user