mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-23 07:43:10 +00:00
gets rid of ugly casts
This commit is contained in:
parent
e3fd2fada8
commit
6c32f6b835
@ -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."
|
||||
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user