mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
reduce futures dep
This commit is contained in:
@ -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"] }
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user