Function: poll()
poll<
T,A>(producer,options):AsyncGenerator<T,void,void>
Async iterable that drives a periodic poll. Each iteration:
- Builds a PollContext (
attempt,previous,signal, sharedattributes) and callsproducer(ctx); yields the resolved value (subject tofilter). - Evaluates
options.predicate(value, ctx); stops when it returns (or resolves to)false. - Sleeps
options.intervalMsbefore the next attempt.
The first call runs immediately (no leading sleep) so the consumer
sees a value without waiting an interval. Errors thrown by
producer propagate through the generator.
poll always creates an internal AbortController and exposes
internal.signal as ctx.signal, so producers can rely on a
defined signal without a nullish check. The external
options.signal is tied in, and a try/finally aborts the
internal signal when the consumer breaks out of the for await
(or the loop throws), so any producer work still holding the
signal sees the cancellation too.
Type Parameters
Section titled “Type Parameters”T
A = Record<string, unknown>
Parameters
Section titled “Parameters”producer
Section titled “producer”PollProducer<T, A>
options
Section titled “options”PollOptions<T, A>
Returns
Section titled “Returns”AsyncGenerator<T, void, void>
Example
Section titled “Example”for await (const msg of poll( async ({ signal }) => client.genie.getMessage({ ... }, { abortSignal: signal }), { intervalMs: 250, predicate: (m) => !TERMINAL_STATUSES.has(m.status), signal: controller.signal, },)) { render(msg);}