Skip to content

Commit

Permalink
explicit loops continuation, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Aug 13, 2024
1 parent 8b76025 commit f987bb9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions waku/waku_sync/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -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:
Expand All @@ -484,13 +489,16 @@ proc periodicPrune(self: WakuSync, callback: PruneCallback) {.async.} =
continue

if cursor.isNone():
# no more pages, stop
break

self.pruneStart = pruneStop
pruneStop = getNowInNanosecondTime() - self.syncRange.nanos

debug "periodic prune done", storageSize = self.storage.len

continue

proc start*(self: WakuSync) =
self.started = true

Expand Down

0 comments on commit f987bb9

Please sign in to comment.