Ed

APIs can be slow or hang forever. Let's implement a timeout that cancels the request if it takes too long using Promise.race().

Your Task:

  • Create a withTimeout(promise, ms) function
  • It races the original promise against a timeout
  • If timeout wins, reject with "Request timed out"
  • If original promise wins, return its result
  • Use Promise.race() for the racing logic
TypeScript Solution
Loading...

Submit your code to see test results