Poll Until a Typed Result Is Ready

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write pollUntil(check, isDone, interval, maxTries): call the async function check, and if isDone of its result is true, resolve with that result; otherwise wait interval milliseconds and try again, calling check at most maxTries times before rejecting with an Error. Type it generically, so the promise resolves to check's own result type and isDone is given that type too.

Your code must pass

  • Resolves with the first result that passes
  • Gives up after maxTries
  • Shows isDone every result in order
  • Has no type errors
  • Resolves with check's result type
  • isDone gets check's result type