chore: create TimeoutError only when needed (#11121)

This commit is contained in:
Nikolay Vitkov 2023-10-11 19:15:06 +02:00 committed by GitHub
parent a3fce3118a
commit e34716ab0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,16 +26,15 @@ export class Deferred<T, V extends Error = Error> {
this.#resolver = resolve;
});
#timeoutId: ReturnType<typeof setTimeout> | undefined;
#timeoutError: TimeoutError;
#timeoutError: TimeoutError | undefined;
constructor(opts?: DeferredOptions) {
this.#timeoutError = new TimeoutError(opts && opts.message);
this.#timeoutId =
opts && opts.timeout > 0
? setTimeout(() => {
this.reject(this.#timeoutError);
}, opts.timeout)
: undefined;
if (opts && opts.timeout > 0) {
this.#timeoutError = new TimeoutError(opts.message);
this.#timeoutId = setTimeout(() => {
this.reject(this.#timeoutError!);
}, opts.timeout);
}
}
#finish(value: T | V | TimeoutError) {