chore: create TimeoutError only when needed (#11121)
This commit is contained in:
parent
a3fce3118a
commit
e34716ab0e
@ -26,16 +26,15 @@ export class Deferred<T, V extends Error = Error> {
|
|||||||
this.#resolver = resolve;
|
this.#resolver = resolve;
|
||||||
});
|
});
|
||||||
#timeoutId: ReturnType<typeof setTimeout> | undefined;
|
#timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||||
#timeoutError: TimeoutError;
|
#timeoutError: TimeoutError | undefined;
|
||||||
|
|
||||||
constructor(opts?: DeferredOptions) {
|
constructor(opts?: DeferredOptions) {
|
||||||
this.#timeoutError = new TimeoutError(opts && opts.message);
|
if (opts && opts.timeout > 0) {
|
||||||
this.#timeoutId =
|
this.#timeoutError = new TimeoutError(opts.message);
|
||||||
opts && opts.timeout > 0
|
this.#timeoutId = setTimeout(() => {
|
||||||
? setTimeout(() => {
|
this.reject(this.#timeoutError!);
|
||||||
this.reject(this.#timeoutError);
|
}, opts.timeout);
|
||||||
}, opts.timeout)
|
}
|
||||||
: undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish(value: T | V | TimeoutError) {
|
#finish(value: T | V | TimeoutError) {
|
||||||
|
Loading…
Reference in New Issue
Block a user