repeatUntil()function

repeatUntil(source: AsyncIterable<T, R | undefined, N | undefined>, ...signals: [PromiseLike<R>, ...PromiseLike<R>[]]): AsyncGenerator<T, R | undefined, N | undefined>
ParamType
sourceAsyncIterable<T, R
undefined, N
undefined>
The source sequence to relay values from. required
signals[PromiseLike<R>, ...PromiseLike<R>[]]
One or more promises that, when resolved, abort the relay and end the sequence. required
Return
AsyncGenerator<T, R | undefined, N | undefined>
The value the winning abort signal resolved with, or the source's own return value if it finishes first.
Throws
UnexpectedError
If the source iterator's return() does not return a done result.

Infinite sequence that relays a source sequence until one of the abort signals resolves.

  • Races each step of source against the supplied signal promises; when a signal wins, tells the source iterator to clean up and returns the signal's value.

Examples

for await (const item of repeatUntil(source, stopSignal)) doSomething(item);