@epikodelabs/streamix / src/public-api / iterate
Function: iterate()
iterate<
T>(source):AsyncIterableIterator<T>
Defined in: projects/libraries/streamix/src/lib/atoms/iterate.ts:25
Creates an async iterable from an atom.
Yields the current value immediately, then yields subsequent values whenever the atom emits. The iterable completes when the atom is disposed.
Type Parameters
T
T
Parameters
source
The atom or async iterable to iterate over.
Atom<T> | AsyncIterable<T, any, any>
Returns
AsyncIterableIterator<T>
An async iterable iterator that yields source values.
Example
ts
const a = atom(0);
setTimeout(() => a.next(1), 10);
setTimeout(() => a.next(2), 20);
setTimeout(() => a.dispose(), 30);
for await (const value of iterate(a)) {
console.log(value); // 0, 1, 2
}