1
0
mirror of https://github.com/actix/actix-website synced 2025-03-19 06:12:41 +01:00

32 lines
774 B
Rust
Raw Normal View History

2018-05-23 20:39:15 -07:00
// <signals>
2020-11-27 01:10:05 +00:00
use actix_web::{rt::System, web, App, HttpResponse, HttpServer};
2018-05-23 20:39:15 -07:00
use std::sync::mpsc;
use std::thread;
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2020-01-02 12:56:32 +06:00
async fn main() {
2018-05-23 20:39:15 -07:00
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
2019-12-29 03:32:56 +09:00
let sys = System::new("http-server");
2019-06-13 17:10:51 -04:00
2022-02-26 03:56:24 +00:00
let srv = HttpServer::new(|| App::new().route("/", web::get().to(HttpResponse::Ok)))
.bind(("127.0.0.1", 8080))?
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
.run();
2019-06-13 17:10:51 -04:00
2020-01-02 12:56:32 +06:00
let _ = tx.send(srv);
sys.run()
2018-05-23 20:39:15 -07:00
});
2020-01-02 12:56:32 +06:00
let srv = rx.recv().unwrap();
// pause accepting new connections
srv.pause().await;
// resume accepting new connections
srv.resume().await;
// stop server
srv.stop(true).await;
2018-05-23 20:39:15 -07:00
}
// </signals>