cf.completefrontend

Write the codeMedium

Write withTimeout(promise, ms): reject if a promise takes longer than ms to settle.

Settle like promise if it settles in time. Otherwise reject with an Error whose name is TimeoutError. Don't leave the timer running after promise has settled.

Write this
function withTimeout(promise, ms) {
  // your code
}
 
// const user = await withTimeout(getUser(), 2000); // rejects after 2 s if getUser is slower

Solve it in the editor, with tests

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…