Type Alias: ConcurIterable()<Value>
ConcurIterable<
Value
>: (apply
) =>Promise
<void
>
Represents a lazy collection of values, each of type Value
, that can be
iterated concurrently.
The collection can be iterated by invoking the concur iterable with an
apply
callback. The callback is applied to each value in the collection,
potentially asynchronously, in some order.
Invoking the concur iterable returns a promise that resolves when apply
has been applied to each value in the concur iterable and each result
returned by apply
is awaited.
A concur iterable is effectively a cold push-based observable backed by some asynchronous operations.
Type Parameters
• Value
Parameters
apply
ConcurIterableApply
<Value
>
Returns
Promise
<void
>
Example
import { asConcur, mapConcur, pipe } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
const concurIterable = pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
mapConcur(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
)
await concurIterable(console.log)
// NOTE: This order may change between runs
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
Since
v0.0.2