Sleep Until Done or Aborted
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Export a class AbortError that extends Error and has the name AbortError. Then write sleep(ms, signal?): a promise that resolves with nothing after ms milliseconds, or rejects with an AbortError as soon as the optional AbortSignal is aborted (straight away if it already is), clearing its timer. Type it so it resolves to void, the wait must be a number and the signal, if given, a real AbortSignal.
Your code must pass
- Resolves after the wait
- Rejects with an AbortError when aborted
- Rejects straight away for an aborted signal
- Has no type errors
- Resolves with nothing
- Takes a number and an optional AbortSignal