Repository navigation
AsyncReader.Class.AsyncIteratorReader
tedious-plus / AsyncReader / AsyncIteratorReader
Defined in: AsyncReader.ts:70
A reader for the values of an async iterable, for procedural processing (as an alternative to a
for await loop).
Usage:
await using reader = new AsyncIteratorReader(iterable);
const firstValue = await reader.read();
const secondValue = await reader.read();Behavior:
-
read()returnsundefinedat the end of the iteration. Ifundefinedcan be a legitimate value of the iterable, usereadResult()instead. - After the end has been reached, after an error or after
close(),read()returnsundefinedwithout accessing the underlying iterator again. - If the underlying iterator fails, the promise returned by
read()is rejected. The iteration is then considered finished, as in afor awaitloop. -
close()terminates the iteration early by callingreturn()on the underlying iterator. This has the same effect as exiting afor awaitloop early.close()is called implicitly at the end of the scope of anawait usingdeclaration. -
read()must not be called again before the promise of the previous call has settled. - The remaining values can also be consumed with a
for awaitloop over the reader. Exiting that loop early closes the reader.
T
-
AsyncReader<T> AsyncDisposable
new AsyncIteratorReader<T>(iterable): AsyncIteratorReader<T>;Defined in: AsyncReader.ts:82
Creates a reader for an async iterable.
AsyncIterable<T>
The async iterable whose values are to be read.
AsyncIteratorReader<T>
get done(): boolean;Defined in: AsyncReader.ts:89
Returns true if the iteration has finished, i.e. the end has been reached, an error has occurred
or the reader has been closed.
boolean
[asyncDispose](): Promise<void>;Defined in: AsyncReader.ts:139
Closes the reader. Called implicitly at the end of the scope of an await using declaration.
Promise<void>
AsyncDisposable.[asyncDispose]
[asyncIterator](): AsyncGenerator<T, void, undefined>;Defined in: AsyncReader.ts:146
Allows the remaining values to be consumed with a for await loop.
Exiting the loop early closes the reader.
AsyncGenerator<T, void, undefined>
close(): Promise<void>;Defined in: AsyncReader.ts:130
Terminates the iteration early. Has no effect if the iteration has already finished, so it can be called multiple times (idempotent).
Calls return() on the underlying iterator, if available, and waits for its completion.
Promise<void>
read(): Promise<T | undefined>;Defined in: AsyncReader.ts:98
Reads the next value.
Promise<T | undefined>
A promise for the next value, or undefined if the iteration has finished.
readResult(): Promise<IteratorResult<T, undefined>>;Defined in: AsyncReader.ts:106
Reads the next value and returns it as an IteratorResult.
Use this method instead of read() if undefined can be a legitimate value of the iterable.
Promise<IteratorResult<T, undefined>>