Poll Until (with Timeout + Abort)

intermediate
By FrontendAtlas Editorial · Updated Nov 22, 2026
Implement pollUntil(check, { interval, timeout, signal }) so a real deadline, cancellation, or the first truthy check settles the returned Promise exactly once. The deadline must remain active even while an asynchronous check is still pending, and no retry may be scheduled after settlement.

Arguments

  • check: () => T | Promise<T> — A function that returns a value (or Promise). A truthy result ends polling and becomes the resolve value.
  • options: { interval?: number, timeout?: number, signal?: AbortSignal } — Polling configuration. interval is the delay between attempts. timeout is the max time to wait. signal cancels polling.

Returns

Promise<T> — Resolves with the first truthy value returned by check, or rejects on timeout/abort.

Solution idea

Run the first check immediately, but keep a separate deadline timer that can settle polling even when the check never settles. Route success, check failure, timeout, and abort through one idempotent settlement helper, and guard immediately after every await before scheduling another attempt.

Examples
const result = await pollUntil(async () => {
  const status = await fetchStatus();
  return status === 'ready' ? status : false;
}, { interval: 200, timeout: 5000 });

const ac = new AbortController();
const p = pollUntil(() => isReady(), { interval: 100, signal: ac.signal });
ac.abort(); // cancels polling

Public interview reports

These public, self-reported interview accounts informed this practice version. The exercise is modelled on reported rounds, not copied from them, and the reports are not verified official questions or endorsements.

Reported in a public ElevenLabs interview account. ElevenLabs frontend interview questions