1
0
mirror of https://github.com/actix/actix-website synced 2025-02-23 20:53:01 +01:00

35 lines
797 B
Rust
Raw Normal View History

2018-05-23 20:39:15 -07:00
// <signals>
2019-12-29 03:32:56 +09:00
use actix_rt::System;
2019-06-13 17:10:51 -04:00
use actix_web::{web, App, HttpResponse, HttpServer};
2018-05-23 20:39:15 -07:00
use std::sync::mpsc;
use std::thread;
2020-01-02 12:56:32 +06:00
#[actix_rt::main]
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
2020-01-02 12:56:32 +06:00
let srv = HttpServer::new(|| {
2019-06-13 17:10:51 -04:00
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
2018-05-23 20:39:15 -07:00
})
2020-01-02 12:56:32 +06:00
.bind("127.0.0.1:8088")?
2019-06-13 17:10:51 -04:00
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
2019-12-29 03:32:56 +09:00
.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>