1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

reduce futures dep

This commit is contained in:
Rob Ede
2022-03-06 00:15:16 +00:00
parent c5f2a8fcc7
commit e8cd22d2f2
25 changed files with 62 additions and 59 deletions

View File

@ -6,6 +6,6 @@ description = "Send a request to the server to shut it down"
[dependencies]
actix-web = "4"
env_logger = "0.9"
futures = "0.3"
tokio = { version = "1.16", features = ["signal"] }

View File

@ -1,5 +1,4 @@
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
use futures::executor;
use std::{sync::mpsc, thread};
#[get("/hello")]
@ -37,16 +36,16 @@ async fn main() -> std::io::Result<()> {
.bind(&bind)?
.run();
// clone the Server handle
// clone the server handle
let srv = server.handle();
thread::spawn(move || {
// wait for shutdown signal
rx.recv().unwrap();
// stop server gracefully
executor::block_on(srv.stop(true))
// send stop server gracefully command
srv.stop(true)
});
// run server
// run server until stopped (either by ctrl-c or stop endpoint)
server.await
}