Skip to content

Interface: PollOptions\<T, A\>

T

A = Record<string, unknown>

optional attributes?: A

Initial value for ctx.attributes. Defaults to {}. The same object is reused across iterations, so callers can pre-populate fields (timers, retry counters, etc.) and the producer / predicate can mutate them in place.


optional filter?: ((value, ctx) => boolean | PromiseLike<boolean>) | "distinct"

Predicate evaluated against each yielded value: return true to keep it, false to skip it (without stopping the loop). May be sync or async - a PromiseLike<boolean> is awaited before the decision is made. Receives the same PollContext as the producer (same signal, same attributes bag). The special value "distinct" skips a value that deep-equals the previous one.


intervalMs: number

Milliseconds to wait between polls.


optional predicate?: (value, ctx) => boolean | PromiseLike<boolean>

Predicate evaluated against each yielded value: return true to keep polling, false to stop. May be sync or async. Omit to poll forever (the consumer stops by breaking out of the loop or by aborting signal).

T

PollContext<T, A>

boolean | PromiseLike<boolean>


optional signal?: AbortSignal

External cancellation handle. Tied into the internal signal that poll hands to producer, so aborting it tears down both the in-flight request and the inter-poll sleep.


optional timeoutMs?: number

Hard upper bound on the total lifetime of the poll loop, in milliseconds. When the budget elapses, poll aborts its internal signal so the in-flight producer and inter-poll sleep both tear down promptly, and the loop throws the TimeoutError DOMException produced by AbortSignal.timeout(timeoutMs). The budget starts ticking the moment the generator is created.