Skip to main content

Function: cycleAsync()

cycleAsync<Value>(asyncIterable): AsyncIterable<Value, any, any>

Returns an infinite async iterable that repeatedly yields the values of asyncIterable.

WARNING: This function does not buffer the values of asyncIterable for future cycles. It reiterates asyncIterable each cycle.

Type Parameters

Value

Parameters

asyncIterable

AsyncIterable<Value, any, any>

Returns

AsyncIterable<Value, any, any>

Example

import { asAsync, cycleAsync, joinAsync, mapAsync, pipe, takeAsync } from 'lfi'

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

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
mapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
cycleAsync,
takeAsync(6),
joinAsync(`, `),
),
)
//=> /slɑθ/, /ˈleɪzi/, /sliːp/, /slɑθ/, /ˈleɪzi/, /sliːp/
Playground

Since

v0.0.1

Defined in

generators.d.ts:348