mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-07-27 12:03:20 +00:00
adds missing mapFuture operation to SafeAsyncIter
This commit is contained in:
parent
4b9d967b93
commit
b158d43729
@ -34,6 +34,7 @@ import ./iter
|
||||
## - next - to get the next item from the async iterator
|
||||
## - items - to iterate over the async iterator
|
||||
## - pairs - to iterate over the async iterator and return the index of each item
|
||||
## - mapFuture - to convert a (raising) Future[T] to a (raising) Future[U] using a function fn: auto -> Future[U] - we use auto to handle both raising and non-raising futures
|
||||
## - mapAsync - to convert a regular sync iterator (Iter) to an async iter (SafeAsyncIter)
|
||||
## - map - to convert one async iterator (SafeAsyncIter) to another async iter (SafeAsyncIter)
|
||||
## - mapFilter - to convert one async iterator (SafeAsyncIter) to another async iter (SafeAsyncIter) and apply filtering at the same time
|
||||
@ -150,6 +151,12 @@ iterator pairs*[T](self: SafeAsyncIter[T]): auto {.inline.} =
|
||||
yield (i, self.next())
|
||||
inc(i)
|
||||
|
||||
proc mapFuture*[T, U](
|
||||
fut: auto, fn: SafeFunction[T, U]
|
||||
): Future[U] {.async: (raises: [CancelledError]).} =
|
||||
let t = await fut
|
||||
await fn(t)
|
||||
|
||||
proc mapAsync*[T, U](
|
||||
iter: Iter[T], fn: SafeFunction[T, ?!U], finishOnErr: bool = true
|
||||
): SafeAsyncIter[U] =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user