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 interviewPractice solo
3 test cases. No second person needed.