Repository navigation
AsyncReader.Class.AsyncReaderIterator
tedious-plus / AsyncReader / AsyncReaderIterator
Defined in: AsyncReader.ts:185
An async iterator for the values of an AsyncReader.
The object is both the iterable and the iterator (like an async generator object), so it can be
used directly in a for await loop. It is single-pass: a second loop continues where the first one
stopped.
Usage:
for await (const value of new AsyncReaderIterator(reader)) {
console.log(value);
}Behavior:
- The iteration ends when
read()returnsundefined. - If
read()fails, the promise returned bynext()is rejected, i.e. the error is thrown within thefor awaitloop. The iteration is then considered finished. - The reader is closed exactly once by this object, however the iteration ends: at the end of the
values, after an error of
read(), or when thefor awaitloop is exited early (bybreak,returnor an exception in the loop body), in which casereturn()is called implicitly. Sinceclose()must be idempotent (see AsyncReader.close), the reader may also be closed elsewhere, e.g. by anawait usingdeclaration. -
next()must not be called again before the promise of the previous call has settled. Afor awaitloop never does that.
T
-
AsyncIterator<T,undefined> -
AsyncIterable<T> AsyncDisposable
new AsyncReaderIterator<T>(reader): AsyncReaderIterator<T>;Defined in: AsyncReader.ts:196
Creates an async iterator for a reader.
AsyncReader<T>
The reader whose values are to be iterated.
AsyncReaderIterator<T>
[asyncDispose](): Promise<void>;Defined in: AsyncReader.ts:241
Terminates the iteration. Called implicitly at the end of the scope of an await using declaration.
Promise<void>
AsyncDisposable.[asyncDispose]
[asyncIterator](): this;Defined in: AsyncReader.ts:235
Returns this object, so that it can be used in a for await loop.
this
AsyncIterable.[asyncIterator]
next(): Promise<IteratorResult<T, undefined>>;Defined in: AsyncReader.ts:202
Returns the next value of the reader as an IteratorResult.
Promise<IteratorResult<T, undefined>>
AsyncIterator.next
return(): Promise<IteratorResult<T, undefined>>;Defined in: AsyncReader.ts:226
Terminates the iteration early and closes the reader. Has no effect if the iteration has already
finished, because the reader has then already been closed. Called implicitly when a for await
loop is exited early.
Promise<IteratorResult<T, undefined>>
AsyncIterator.return