From f987bb9a402bee24ff42867a1757883219c88c09 Mon Sep 17 00:00:00 2001 From: SionoiS Date: Wed, 7 Aug 2024 15:35:25 -0400 Subject: [PATCH] explicit loops continuation, comments --- waku/waku_sync/protocol.nim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/waku/waku_sync/protocol.nim b/waku/waku_sync/protocol.nim index 6ea8c879e1..0a5e6e49d8 100644 --- a/waku/waku_sync/protocol.nim +++ b/waku/waku_sync/protocol.nim @@ -132,6 +132,8 @@ proc request( return ok(hashes) + continue + proc storeSynchronization*( self: WakuSync, peerInfo: Option[RemotePeerInfo] = none(RemotePeerInfo) ): Future[Result[(seq[WakuMessageHash], RemotePeerInfo), string]] {.async.} = @@ -184,6 +186,8 @@ proc handleSyncSession( client = conn.peerId, payload = reconciled.payload + continue + proc initProtocolHandler(self: WakuSync) = proc handle(conn: Connection, proto: string) {.async, closure.} = debug "sync session requested", @@ -394,8 +398,7 @@ proc new*( proc periodicSync(self: WakuSync, callback: TransferCallback) {.async.} = debug "periodic sync initialized", interval = $self.syncInterval - # infinite loop - while true: + while true: # infinite loop await sleepAsync(self.syncInterval) debug "periodic sync started" @@ -437,6 +440,8 @@ proc periodicSync(self: WakuSync, callback: TransferCallback) {.async.} = debug "periodic sync done", hashSynced = hashes.len + continue + proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} = debug "periodic prune initialized", interval = $self.syncInterval @@ -448,8 +453,7 @@ proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} = # Default T minus 55m var pruneStop = getNowInNanosecondTime() - self.syncRange.nanos - # infinite loop - while true: + while true: # infinite loop await sleepAsync(self.syncInterval) debug "periodic prune started", @@ -475,6 +479,7 @@ proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} = break if elements.len == 0: + # no elements to remove, stop break for (hash, timestamp) in elements: @@ -484,6 +489,7 @@ proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} = continue if cursor.isNone(): + # no more pages, stop break self.pruneStart = pruneStop @@ -491,6 +497,8 @@ proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} = debug "periodic prune done", storageSize = self.storage.len + continue + proc start*(self: WakuSync) = self.started = true