From e34716ab0eb8b8bf4427a71394259eb3bc9c09ca Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:15:06 +0200 Subject: [PATCH] chore: create TimeoutError only when needed (#11121) --- packages/puppeteer-core/src/util/Deferred.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/puppeteer-core/src/util/Deferred.ts b/packages/puppeteer-core/src/util/Deferred.ts index 47184aa2b43..a512a928728 100644 --- a/packages/puppeteer-core/src/util/Deferred.ts +++ b/packages/puppeteer-core/src/util/Deferred.ts @@ -26,16 +26,15 @@ export class Deferred { this.#resolver = resolve; }); #timeoutId: ReturnType | 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) {