Delay_for causes my whole program to wait

i am using delay_for inside tokio::spawn to sleep for a given time, but i want only the task to sleep, not the whole applicaiton? how can i achieve this behavior?

Other independently spawned tasks should definitely not go to sleep when you use delay_for. Can you post some more details on what's going on?

i tested it by sending 100 files, the output on the screen shows after every 3 seconds

    loop {
        let task = timeout(config.timeout, async move {
            let mut tls_stream = tls_acceptor.accept(tcp_stream).await.unwrap();
            let _file_processor = FileProcessor::new(&config, &mut tls_stream).await.unwrap();

            tokio::time::delay_for(std::time::Duration::from_secs(3)).await;
        });

        tokio::spawn(task);
    }

It's not obvious from this snippet what's wrong. I need more context.

@alice my bad, to sender i wrote is synchronous :crazy_face: delay_for is working as expected, i guess i am tried after a long day work..

1 Like