Problem, as an interviewer would state it:
"Write debounceAsync(fn, wait) — like regular debounce, but fn returns a promise, and EVERY caller (even ones from earlier in the burst) needs to get back a promise that resolves with the eventual, single real result."
Examples:
const search = debounceAsync(fetchResults, 300);
const [r1, r2, r3] = await Promise.all([search("r"), search("re"), search("rea")]);
// only ONE real fetchResults call happens (with "rea"); r1 === r2 === r3
Clarifying questions expected:
- Should EVERY caller in the burst resolve, or only the last one (with earlier callers left hanging forever)?
- What happens if the eventual real call rejects — do ALL pending callers reject too?
- Does this need to interoperate with a plain, non-async debounce, or is it a separate implementation?
Code / implementation expected: Yes — real, direct proof that 3 rapid calls in a burst produce exactly 1 real underlying invocation, with all 3 callers' promises resolving to that identical result.