Add Concurrency to Server

This commit is contained in:
GuilhermeWerner
2021-01-19 12:15:32 -03:00
parent 3d6239e514
commit 4a2a783205

View File

@ -9,7 +9,12 @@ async fn main() {
loop {
// The second item contains the IP and port of the new connection.
let (socket, _) = listener.accept().await.unwrap();
process(socket).await;
// A new task is spawned for each inbound socket. The socket is
// moved to the new task and processed there.
tokio::spawn(async move {
process(socket).await;
});
}
}