Event Loop & Timers

Polling Function with Termination Check

mediumJS SpecificJS / TS3 tests

Problem Statement

Implement `poll(fn, validate, interval, maxAttempts)` that repeatedly executes async function `fn` every `interval` milliseconds until `validate(result)` returns true or `maxAttempts` is reached.

Examples

Example 1:
let status = 'pending';
setTimeout(() => { status = 'ready'; }, 80);
await poll(async () => status, (s) => s === 'ready', 20, 10); // 'ready'
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.