Wraps a promise with a timeout. If the promise does not settle within the specified time, it rejects with a Timeout error.
Timeout
The type of the promise's resolved value.
The promise to wrap with a timeout.
Timeout duration in milliseconds.
Optional timeout error message (default: "Timeout").
A promise that resolves or rejects like the original promise, or rejects on timeout.
const result = await timeout( new Promise(res => setTimeout(() => res("Done"), 2000)), 1000).catch(err => err.message);console.log(result); // "Timeout" Copy
const result = await timeout( new Promise(res => setTimeout(() => res("Done"), 2000)), 1000).catch(err => err.message);console.log(result); // "Timeout"
1.1.0
Wraps a promise with a timeout. If the promise does not settle within the specified time, it rejects with a
Timeouterror.