Skip to content

handle tokio delay_for block #2349

Answered by fakeshadow
daiguadaidai asked this question in Q&A
Discussion options

You must be logged in to vote
use std::{
    io::{Read, Write},
    net::TcpStream,
};

use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};

async fn handle_hello() -> impl Responder {
    HttpResponse::Ok().body("get api hello!")
}

#[get("/world")]
async fn handle_world() -> impl Responder {
    println!("tokio sleep start");
    tokio::time::delay_for(tokio::time::Duration::from_secs(5)).await;
    println!("tokio sleep end");
    HttpResponse::Ok().body("get api world!")
}

fn config(cfg: &mut web::ServiceConfig) {
    cfg.service(web::resource("/hello").route(web::get().to(handle_hello)))
        .service(handle_world);
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let server = 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@daiguadaidai
Comment options

Answer selected by daiguadaidai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants