1
0
mirror of https://github.com/actix/actix-website synced 2025-01-23 00:25:55 +01:00

35 lines
793 B
Rust
Raw Normal View History

2018-05-23 20:39:15 -07:00
// <signals>
2022-02-26 05:22:21 +00:00
use actix_web::{web, App, HttpResponse, HttpServer};
use std::io;
2018-05-23 20:39:15 -07:00
2022-02-26 05:22:21 +00:00
#[tokio::main]
async fn main() -> io::Result<()> {
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();
2018-05-23 20:39:15 -07:00
2022-02-26 05:22:21 +00:00
// obtain handle to server
let srv_handle = srv.handle();
2019-06-13 17:10:51 -04:00
2022-02-26 05:22:21 +00:00
// spawn server as Tokio task to start processing connections
tokio::spawn(srv);
2020-01-02 12:56:32 +06:00
// pause accepting new connections
2022-02-26 05:22:21 +00:00
srv_handle.pause().await;
2020-01-02 12:56:32 +06:00
// resume accepting new connections
2022-02-26 05:22:21 +00:00
srv_handle.resume().await;
// stop server gracefully
srv_handle.stop(true).await;
Ok(())
2018-05-23 20:39:15 -07:00
}
// </signals>
2022-02-26 05:22:21 +00:00
#[allow(dead_code)]
fn run_main() {
let _ = main();
}