mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
review server section
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
// <setup>
|
||||
use actix_web::{web, App, Responder};
|
||||
use actix_web::{web, App, Responder, HttpServer};
|
||||
|
||||
async fn index() -> impl Responder {
|
||||
"Hello world!"
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().service(
|
||||
web::scope("/app").route("/index.html", web::get().to(index)),
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix_web::{web, App, HttpResponse};
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
pub mod app;
|
||||
pub mod combine;
|
||||
@ -10,7 +10,7 @@ pub mod vh;
|
||||
|
||||
// <multi>
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(
|
||||
|
@ -4,29 +4,31 @@ use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
thread::spawn(move || {
|
||||
let sys = System::new("http-server");
|
||||
|
||||
let addr = HttpServer::new(|| {
|
||||
let srv = HttpServer::new(|| {
|
||||
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
|
||||
.run();
|
||||
|
||||
let _ = tx.send(addr);
|
||||
let _ = tx.send(srv);
|
||||
sys.run()
|
||||
});
|
||||
|
||||
let addr = rx.recv().unwrap();
|
||||
let _ = System::new("`actix_server::ServerCommand::Pause`")
|
||||
.block_on(addr.pause());
|
||||
let _ = System::new("`actix_server::ServerCommand::Resume`")
|
||||
.block_on(addr.resume());
|
||||
let _ = System::new("`actix_server::ServerCommand::Stop`")
|
||||
.block_on(addr.stop(true));
|
||||
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;
|
||||
}
|
||||
// </signals>
|
||||
|
Reference in New Issue
Block a user