From: Martin Pitt Date: Fri, 16 Sep 2022 07:03:46 +0000 (+0200) Subject: async-http: Serve requests in parallel in threads X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=commitdiff_plain;h=c4531591e9396d86e57f32badcd8dd05edaafbfe async-http: Serve requests in parallel in threads Use async_std::task::spawn to launch a request in a thread. Now even synchronous sleep does not block other requests, as long as they don't exceed the thread pool capacity. --- diff --git a/async-http/src/main.rs b/async-http/src/main.rs index cf0b46d..c288408 100644 --- a/async-http/src/main.rs +++ b/async-http/src/main.rs @@ -15,7 +15,7 @@ async fn main() { listener.incoming().for_each_concurrent(/* limit */ None, |tcpstream| async move { let tcpstream = tcpstream.unwrap(); - handle_connection(tcpstream).await; + task::spawn(handle_connection(tcpstream)); }).await; }