Execute a promise with a timeout
Races the provided promise against a timeout. If the timeout expires before the promise resolves, a TimeoutError is thrown.
Type of the promise result
Promise to execute with timeout
Timeout in milliseconds
Optional
Optional custom error message
Promise that resolves with the result or rejects with TimeoutError
If operation exceeds timeout
const result = await withTimeout( fetchFromAPI('/endpoint'), 5000, 'API request timed out'); Copy
const result = await withTimeout( fetchFromAPI('/endpoint'), 5000, 'API request timed out');
0.8.0
Execute a promise with a timeout
Races the provided promise against a timeout. If the timeout expires before the promise resolves, a TimeoutError is thrown.