mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
Merge pull request #254 from Dowwie/master
removed control-C handling because actix-server natively supports it
This commit is contained in:
commit
691812f3f4
@ -13,7 +13,6 @@ deadpool-postgres = "0.5.0"
|
|||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
serde = { version = "1.0.104", features = ["derive"] }
|
serde = { version = "1.0.104", features = ["derive"] }
|
||||||
tokio = { version = "0.2.11", features = ["signal"] }
|
|
||||||
tokio-pg-mapper = "0.1.4"
|
tokio-pg-mapper = "0.1.4"
|
||||||
tokio-pg-mapper-derive = "0.1.4"
|
tokio-pg-mapper-derive = "0.1.4"
|
||||||
tokio-postgres = "0.5.1"
|
tokio-postgres = "0.5.1"
|
||||||
|
@ -110,7 +110,6 @@ mod handlers {
|
|||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use handlers::add_user;
|
use handlers::add_user;
|
||||||
use tokio::signal::unix::{signal, SignalKind};
|
|
||||||
use tokio_postgres::NoTls;
|
use tokio_postgres::NoTls;
|
||||||
|
|
||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
@ -129,15 +128,5 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.run();
|
.run();
|
||||||
println!("Server running at http://{}/", config.server_addr);
|
println!("Server running at http://{}/", config.server_addr);
|
||||||
|
|
||||||
let srv = server.clone();
|
|
||||||
let mut stream = signal(SignalKind::interrupt())?;
|
|
||||||
actix_rt::spawn(async move {
|
|
||||||
loop {
|
|
||||||
stream.recv().await;
|
|
||||||
println!("\nSIGINT Received. Stopping server.\n");
|
|
||||||
srv.stop(true).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.await
|
server.await
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ Demonstrates how to shutdown the web server in a couple of ways:
|
|||||||
- Created in response to actix/actix-web#1315
|
- Created in response to actix/actix-web#1315
|
||||||
|
|
||||||
2. sending a SIGINT signal to the server (control-c)
|
2. sending a SIGINT signal to the server (control-c)
|
||||||
|
- actix-server natively supports SIGINT
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
||||||
use futures::executor;
|
use futures::executor;
|
||||||
use std::{sync::mpsc, thread};
|
use std::{sync::mpsc, thread};
|
||||||
use tokio::signal::unix::{signal, SignalKind};
|
|
||||||
|
|
||||||
#[get("/hello")]
|
#[get("/hello")]
|
||||||
async fn hello() -> &'static str {
|
async fn hello() -> &'static str {
|
||||||
@ -51,15 +51,6 @@ async fn main() -> std::io::Result<()> {
|
|||||||
executor::block_on(srv.stop(true))
|
executor::block_on(srv.stop(true))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut stream = signal(SignalKind::interrupt())?;
|
|
||||||
actix_rt::spawn(async move {
|
|
||||||
loop {
|
|
||||||
stream.recv().await;
|
|
||||||
println!("\n*** SIGINT received. Stopping server, gracefully. ***\n");
|
|
||||||
stopper.send(()).unwrap();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// run server
|
// run server
|
||||||
server.await
|
server.await
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user