Report rejection after timeout

This commit is contained in:
Wojciech Pawlik 2021-01-02 18:03:23 +01:00
parent 4f86930f75
commit 3c1c042a00
No known key found for this signature in database
GPG Key ID: EAC4468F0FF70C72
2 changed files with 4 additions and 0 deletions

1
index.d.ts vendored
View File

@ -1,5 +1,6 @@
declare class TimeoutErrorClass extends Error {
readonly name: 'TimeoutError';
readonly promise?: Promise<unknown>;
constructor(message?: string);
}

View File

@ -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);