From 88015be0ead464706fc2c71b561496e4ee3dc358 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Mon, 23 Sep 2024 13:53:55 +0200 Subject: [PATCH] clippy & removed some assumptions --- node/libs/concurrency/src/net/tcp/mod.rs | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/node/libs/concurrency/src/net/tcp/mod.rs b/node/libs/concurrency/src/net/tcp/mod.rs index 097b4e3f..2fc6f7e4 100644 --- a/node/libs/concurrency/src/net/tcp/mod.rs +++ b/node/libs/concurrency/src/net/tcp/mod.rs @@ -17,13 +17,12 @@ pub type Listener = tokio::net::TcpListener; /// Accepts an INBOUND listener connection. pub async fn accept(ctx: &ctx::Ctx, this: &mut Listener) -> ctx::OrCanceled> { - Ok(ctx.wait(this.accept()).await?.map(|(stream, _)| { - // We are the only owner of the correctly opened - // socket at this point so `set_nodelay` should - // always succeed. - stream.set_nodelay(true).unwrap(); - stream - })) + ctx.wait(async { + let stream = this.accept().await?.0; + stream.set_nodelay(true)?; + Ok(stream) + }) + .await } /// Opens a TCP connection to a remote host. @@ -31,14 +30,10 @@ pub async fn connect( ctx: &ctx::Ctx, addr: std::net::SocketAddr, ) -> ctx::OrCanceled> { - Ok(ctx - .wait(tokio::net::TcpStream::connect(addr)) - .await? - .map(|stream| { - // We are the only owner of the correctly opened - // socket at this point so `set_nodelay` should - // always succeed. - stream.set_nodelay(true).unwrap(); - stream - })) + ctx.wait(async { + let stream = tokio::net::TcpStream::connect(addr).await?; + stream.set_nodelay(true)?; + Ok(stream) + }) + .await }