gets rid of ugly casts

This commit is contained in:
Marcin Czenko 2025-03-31 17:56:35 +02:00
parent e3fd2fada8
commit 6c32f6b835
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
4 changed files with 7 additions and 10 deletions

View File

@ -99,13 +99,13 @@ proc advertiseLocalStoreLoop(b: Advertiser) {.async: (raises: []).} =
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)):
if cid =? await 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 cast[Future[?!Cid].Raising([CancelledError])](c)):
if cid =? await c:
await b.advertiseBlock(cid)
trace "Advertiser iterating blocks finished."

View File

@ -245,7 +245,7 @@ proc fetchBatched*(
# )
while not iter.finished:
let blockFutures: seq[Future[?!bt.Block].Raising([CancelledError])] = collect:
let blockFutures = collect:
for i in 0 ..< batchSize:
if not iter.finished:
let address = BlockAddress.init(cid, iter.next())

View File

@ -204,8 +204,7 @@ proc retrieveInfoHash(
torrentDownloader.start()
for blockFut in torrentDownloader.getAsyncBlockIterator():
let blockRes =
await cast[Future[?!(int, seq[byte])].Raising([CancelledError])](blockFut)
let blockRes = await blockFut
without (blockIndex, data) =? (blockRes), err:
error "Error streaming blocks", err = err.msg
resp.status = Http500

View File

@ -293,12 +293,10 @@ asyncchecksuite "RepoStore":
test "Should retrieve block expiration information":
proc unpack(
beIter: Future[?!SafeAsyncIter[BlockExpiration]]
): Future[seq[BlockExpiration]] {.async: (raises: [CatchableError]).} =
beIter: auto
): Future[seq[BlockExpiration]] {.async: (raises: [CancelledError]).} =
var expirations = newSeq[BlockExpiration](0)
without iter =? (
await cast[Future[?!SafeAsyncIter[BlockExpiration]].Raising([CancelledError])](beIter)
), err:
without iter =? (await beIter), err:
return expirations
for beFut in toSeq(iter):
if value =? (await beFut):