use axum::{routing::get, Router};
use axum_server::Handle;
use std::{net::SocketAddr, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let handle = Handle::new();
tokio::spawn(shutdown(handle.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind(addr)
.handle(handle)
.serve(app.into_make_service())
.await
.unwrap();
println!("server is shut down");
}
async fn shutdown(handle: Handle) {
sleep(Duration::from_secs(20)).await;
println!("sending shutdown signal");
handle.shutdown();
}