Async & Promises
Promise with Timeout
easyJS SpecificJS / TS3 tests
Problem Statement
Create a wrapper function `timeout(promise, ms, errorMessage)` that rejects with a custom Error (default: `'Operation timed out'`) if the provided promise does not settle within `ms` milliseconds.
Examples
Example 1:
const slow = new Promise((resolve) => setTimeout(() => resolve('done'), 500));
timeout(slow, 100).catch(err => console.log(err.message)); // 'Operation timed out'JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
3 test cases. No second person needed.