Timeout without error

This commit is contained in:
Federico Brigante 2022-08-01 16:21:43 +07:00 committed by GitHub
parent 200df03007
commit 557dbb019a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -77,12 +77,16 @@ export default function pTimeout(promise, options) {
return;
}
const errorMessage = typeof message === 'string' ? message : `Promise timed out after ${milliseconds} milliseconds`;
const timeoutError = message instanceof Error ? message : new TimeoutError(errorMessage);
if (typeof promise.cancel === 'function') {
promise.cancel();
}
if (message === false) {
resolve();
}
const errorMessage = typeof message === 'string' ? message : `Promise timed out after ${milliseconds} milliseconds`;
const timeoutError = message instanceof Error ? message : new TimeoutError(errorMessage);
reject(timeoutError);
}, milliseconds);