Report rejection after timeout
This commit is contained in:
parent
4f86930f75
commit
3c1c042a00
|
@ -1,5 +1,6 @@
|
|||
declare class TimeoutErrorClass extends Error {
|
||||
readonly name: 'TimeoutError';
|
||||
readonly promise?: Promise<unknown>;
|
||||
constructor(message?: string);
|
||||
}
|
||||
|
||||
|
|
3
index.js
3
index.js
|
@ -40,6 +40,9 @@ const pTimeout = (promise, milliseconds, fallback, options) => {
|
|||
|
||||
if (typeof promise.cancel === 'function') {
|
||||
promise.cancel();
|
||||
} else {
|
||||
// `.catch(undefined)` needed to report `unhandledRejection`
|
||||
timeoutError.promise = promise.catch(undefined);
|
||||
}
|
||||
|
||||
reject(timeoutError);
|
||||
|
|
Loading…
Reference in New Issue