Problem, as an interviewer would state it:
"Write throttleAsync(fn, wait) — like regular throttle, but wraps an async fn. If fn is already IN FLIGHT (a real, pending call), additional calls should not start a redundant second real call — they should share the existing in-flight result."
Examples:
const t = throttleAsync(fetchStatus, 200);
const [a, b, c] = await Promise.all([t(), t(), t()]);
// only ONE real fetchStatus() call happens; a, b, c all resolve to its result
Clarifying questions expected:
- If a call arrives WHILE another is genuinely in flight, does it wait and share that result, or is it dropped entirely?
- Does the throttle window start when the call BEGINS, or only once it genuinely finishes?
- Should a call that arrives just after the window closes trigger a fresh, new real call?
Code / implementation expected: Yes — real, direct proof that 3 near-simultaneous callers, while a call is already in flight, produce exactly 1 real underlying invocation.