uses SafeAsyncIter in "listBlocks" and in "getBlockExpirations"

This commit is contained in:
Marcin Czenko 2025-03-30 20:41:56 +02:00
parent edf4627dbd
commit 4d5dfb15d0
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
2 changed files with 10 additions and 18 deletions

View File

@ -96,28 +96,18 @@ proc advertiseBlock(b: Advertiser, cid: Cid) {.async: (raises: [CancelledError])
proc advertiseLocalStoreLoop(b: Advertiser) {.async: (raises: []).} =
try:
while b.advertiserRunning:
if cidsIter =? await b.localStore.listBlocks(blockType = BlockType.Torrent):
trace "Advertiser begins iterating torrent blocks..."
for c in cidsIter:
if cid =? (await cast[Future[?!Cid].Raising([CancelledError])](c)):
await b.advertiseBlock(cid)
trace "Advertiser iterating torrent blocks finished."
if cidsIter =? await b.localStore.listBlocks(blockType = BlockType.Manifest):
trace "Advertiser begins iterating blocks..."
for c in cidsIter:
if cid =? await c:
if cid =? (await cast[Future[?!Cid].Raising([CancelledError])](c)):
await b.advertiseBlock(cid)
trace "Advertiser iterating blocks finished."
try:
if cids =? await b.localStore.listBlocks(blockType = BlockType.Torrent):
trace "Advertiser begins iterating torrent blocks..."
for c in cids:
if cid =? await c:
await b.advertiseBlock(cid)
trace "Advertiser iterating torrent blocks finished."
if cids =? await b.localStore.listBlocks(blockType = BlockType.Manifest):
trace "Advertiser begins iterating blocks..."
for c in cids:
if cid =? await c:
await b.advertiseBlock(cid)
trace "Advertiser iterating blocks finished."
except CatchableError as e:
error "Error in advertise local store loop", error = e.msgDetail
raiseAssert("Unexpected exception in advertiseLocalStoreLoop")
await sleepAsync(b.advertiseLocalStoreLoopSleep)
except CancelledError:

View File

@ -296,7 +296,9 @@ asyncchecksuite "RepoStore":
beIter: Future[?!SafeAsyncIter[BlockExpiration]]
): Future[seq[BlockExpiration]] {.async: (raises: [CatchableError]).} =
var expirations = newSeq[BlockExpiration](0)
without iter =? (await beIter), err:
without iter =? (
await cast[Future[?!SafeAsyncIter[BlockExpiration]].Raising([CancelledError])](beIter)
), err:
return expirations
for beFut in toSeq(iter):
if value =? (await beFut):