refactor(networking): wait for all futures together in connectToNodes (#1471)

* refactor(networking): wait for all futures together in connectToNodes

* refactor(networking): await fix style
This commit is contained in:
Alvaro Revuelta 2023-01-09 21:45:50 +01:00 committed by GitHub
parent 333ce0a2e1
commit 4eb9375b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -269,10 +269,13 @@ proc connectToNodes*(pm: PeerManager,
source = "api") {.async.} =
info "connectToNodes", len = nodes.len
var futConns: seq[Future[Option[Connection]]]
for node in nodes:
let node = when node is string: parseRemotePeerInfo(node)
else: node
discard await pm.dialPeer(RemotePeerInfo(node), proto, dialTimeout, source)
futConns.add(pm.dialPeer(RemotePeerInfo(node), proto, dialTimeout, source))
await allFutures(futConns)
# The issue seems to be around peers not being fully connected when
# trying to subscribe. So what we do is sleep to guarantee nodes are