Add active waitForMesh proc.
This commit is contained in:
parent
e199782ca1
commit
b32badfe9a
|
@ -147,6 +147,12 @@ proc subscribeRandom*(nodes: seq[PubSub]) {.async.} =
|
||||||
await dialer.switch.connect(node.peerInfo.peerId, node.peerInfo.addrs)
|
await dialer.switch.connect(node.peerInfo.peerId, node.peerInfo.addrs)
|
||||||
dialed.add(node.peerInfo.peerId)
|
dialed.add(node.peerInfo.peerId)
|
||||||
|
|
||||||
|
proc activeWait(
|
||||||
|
interval: Duration, maximum: Moment, timeoutErrorMessage = "Timeout on activeWait"
|
||||||
|
) {.async.} =
|
||||||
|
await sleepAsync(interval)
|
||||||
|
doAssert Moment.now() < maximum, timeoutErrorMessage
|
||||||
|
|
||||||
proc waitSub*(sender, receiver: auto, key: string) {.async.} =
|
proc waitSub*(sender, receiver: auto, key: string) {.async.} =
|
||||||
if sender == receiver:
|
if sender == receiver:
|
||||||
return
|
return
|
||||||
|
@ -201,3 +207,19 @@ proc waitSubGraph*(nodes: seq[PubSub], key: string) {.async.} =
|
||||||
|
|
||||||
await sleepAsync(5.milliseconds)
|
await sleepAsync(5.milliseconds)
|
||||||
doAssert Moment.now() < timeout, "waitSubGraph timeout!"
|
doAssert Moment.now() < timeout, "waitSubGraph timeout!"
|
||||||
|
|
||||||
|
proc waitForMesh*(
|
||||||
|
sender: auto, receiver: auto, key: string, timeoutDuration = 5.seconds
|
||||||
|
) {.async.} =
|
||||||
|
if sender == receiver:
|
||||||
|
return
|
||||||
|
|
||||||
|
let
|
||||||
|
timeoutMoment = Moment.now() + timeoutDuration
|
||||||
|
gossipsubSender = GossipSub(sender)
|
||||||
|
receiverPeerId = receiver.peerInfo.peerId
|
||||||
|
|
||||||
|
while not gossipsubSender.mesh.hasPeerId(key, receiverPeerId):
|
||||||
|
trace "waitForMesh sleeping..."
|
||||||
|
await activeWait(5.milliseconds, timeoutMoment, "waitForMesh timeout!")
|
||||||
|
echo "waitForMesh done!"
|
||||||
|
|
Loading…
Reference in New Issue