Problem, as an interviewer would state it: "Build a client that polls a real endpoint at a fixed interval — WITHOUT letting requests overlap if a previous one is still in flight when the next tick occurs."
Examples:
const poller = createPoller({ intervalMs: 5000, fetchFn, onData });
poller.start(); // polls every 5s, but skips a tick if the previous fetch is still running
Clarifying questions expected:
- If a fetch takes LONGER than the poll interval, should the next tick be skipped entirely, or queued to run immediately once the current one finishes?
- Should the very first poll fire immediately on start(), or only after waiting one full interval?
- What happens to data received out of order, if two requests somehow DID overlap?
Code / implementation expected: Yes — real, direct proof with a deliberately slow first fetch spanning multiple poll intervals, confirming ticks are correctly SKIPPED rather than firing overlapping requests.