Skip to content

Commit 0a92055

Browse files
committed
connection-manager: simplify ConnMap.traverseMaybeWithKey
1 parent 62de5da commit 0a92055

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/ConnMap.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Ouroboros.Network.ConnectionManager.ConnMap
1717
, lookup
1818
, lookupByRemoteAddr
1919
, updateLocalAddr
20-
, traverseMaybeWithKey
20+
, traverseMaybe
2121
) where
2222

2323
import Prelude hiding (lookup)
@@ -248,22 +248,17 @@ updateLocalAddr ConnectionId { remoteAddress, localAddress } (ConnMap m) =
248248
m
249249

250250

251-
traverseMaybeWithKey
251+
traverseMaybe
252252
:: Applicative f
253-
=> (Either peerAddr (ConnectionId peerAddr) -> a -> f (Maybe b))
253+
=> (a -> f (Maybe b))
254254
-> ConnMap peerAddr a
255255
-> f [b]
256-
traverseMaybeWithKey fn =
256+
traverseMaybe fn =
257257
fmap (concat . Map.elems)
258258
. Map.traverseMaybeWithKey
259-
(\remoteAddress st ->
259+
(\_ st ->
260260
fmap (Just . Map.elems)
261-
. Map.traverseMaybeWithKey
262-
(\case
263-
UnknownLocalAddr -> fn (Left remoteAddress)
264-
LocalAddr localAddress -> fn (Right ConnectionId { remoteAddress,
265-
localAddress })
266-
)
261+
. Map.traverseMaybeWithKey (\_ -> fn)
267262
$ st
268263
)
269264
. getConnMap

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,8 @@ with args@Arguments {
528528
-- Spawning one thread for each connection cleanup avoids spending time
529529
-- waiting for locks and cleanup logic that could delay closing the
530530
-- connections and making us not respecting certain timeouts.
531-
asyncs <- State.traverseMaybeWithKey
532-
-- TODO: remove first argument!
533-
(\_peerAddrOrConnId MutableConnState { connStateId, connVar } -> do
531+
asyncs <- State.traverseMaybe
532+
(\MutableConnState { connStateId, connVar } -> do
534533
-- cleanup handler for that thread will close socket associated
535534
-- with the thread. We put each connection in 'TerminatedState' to
536535
-- try that none of the connection threads will enter

0 commit comments

Comments
 (0)