Skip to main content

Function: consumeAsync()

consumeAsync(asyncIterable): Promise<void>

Iterates through asyncIterable causing lazy operations to run.

Parameters

asyncIterable

AsyncIterable<unknown, any, any>

Returns

Promise<void>

Example

import { asAsync, consumeAsync, eachAsync, mapAsync, pipe } from 'lfi'

const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`

const asyncIterable = pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
mapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
eachAsync(console.log),
)
// No output

await consumeAsync(asyncIterable)
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
Playground

Since

v2.0.0

Defined in

side-effects.d.ts:312