From e304ad0f7ea6ca4bacf4992625a6a6a841aa5af7 Mon Sep 17 00:00:00 2001 From: diegomrsantos Date: Thu, 5 Jan 2023 15:02:52 +0100 Subject: [PATCH] Remove unnecessary async (#836) --- libp2p/connmanager.nim | 2 +- libp2p/dialer.nim | 2 +- tests/testconnmngr.nim | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libp2p/connmanager.nim b/libp2p/connmanager.nim index e411d40ad..3c88d2de3 100644 --- a/libp2p/connmanager.nim +++ b/libp2p/connmanager.nim @@ -416,7 +416,7 @@ proc getIncomingSlot*(c: ConnManager): Future[ConnectionSlot] {.async.} = await c.inSema.acquire() return ConnectionSlot(connManager: c, direction: In) -proc getOutgoingSlot*(c: ConnManager, forceDial = false): Future[ConnectionSlot] {.async.} = +proc getOutgoingSlot*(c: ConnManager, forceDial = false): ConnectionSlot {.raises: [Defect, TooManyConnectionsError].} = if forceDial: c.outSema.forceAcquire() elif not c.outSema.tryAcquire(): diff --git a/libp2p/dialer.nim b/libp2p/dialer.nim index 4e39733a4..4f7c03538 100644 --- a/libp2p/dialer.nim +++ b/libp2p/dialer.nim @@ -177,7 +177,7 @@ proc internalConnect( trace "Reusing existing connection", conn, direction = $conn.dir return conn - let slot = await self.connManager.getOutgoingSlot(forceDial) + let slot = self.connManager.getOutgoingSlot(forceDial) conn = try: await self.dialAndUpgrade(peerId, addrs) diff --git a/tests/testconnmngr.nim b/tests/testconnmngr.nim index dda2e3dc1..9a59e61da 100644 --- a/tests/testconnmngr.nim +++ b/tests/testconnmngr.nim @@ -259,11 +259,11 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxConnections = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -271,7 +271,7 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxConnections = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should timeout adding a connection over the limit check not(await connMngr.getIncomingSlot().withTimeout(10.millis)) @@ -286,7 +286,7 @@ suite "Connection Manager": # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -304,11 +304,11 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxOut = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -316,7 +316,7 @@ suite "Connection Manager": let connMngr = ConnManager.new(maxOut = 3) for i in 0..<3: - check await connMngr.getOutgoingSlot().withTimeout(10.millis) + discard connMngr.getOutgoingSlot() # should timeout adding a connection over the limit check not(await connMngr.getIncomingSlot().withTimeout(10.millis)) @@ -332,7 +332,7 @@ suite "Connection Manager": # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot() + discard connMngr.getOutgoingSlot() await connMngr.close() @@ -341,11 +341,11 @@ suite "Connection Manager": var conns: seq[Connection] for i in 0..<3: - check await connMngr.getOutgoingSlot(true).withTimeout(10.millis) + discard connMngr.getOutgoingSlot(true) # should throw adding a connection over the limit expect TooManyConnectionsError: - discard await connMngr.getOutgoingSlot(false) + discard connMngr.getOutgoingSlot(false) await connMngr.close() @@ -354,7 +354,7 @@ suite "Connection Manager": var conns: seq[Connection] for i in 0..<3: - let slot = await ((connMngr.getOutgoingSlot()).wait(10.millis)) + let slot = connMngr.getOutgoingSlot() let conn = getConnection(