From 35504ae0e77077d188719b6e28754703defb4a66 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:57:29 +0100 Subject: [PATCH] refactor: don't expose the deferred (#12130) --- .../puppeteer-core/src/common/CallbackRegistry.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/puppeteer-core/src/common/CallbackRegistry.ts b/packages/puppeteer-core/src/common/CallbackRegistry.ts index ea9f3d5abb5..6b8379177ba 100644 --- a/packages/puppeteer-core/src/common/CallbackRegistry.ts +++ b/packages/puppeteer-core/src/common/CallbackRegistry.ts @@ -31,17 +31,14 @@ export class CallbackRegistry { } catch (error) { // We still throw sync errors synchronously and clean up the scheduled // callback. - callback.promise - .valueOrThrow() - .catch(debugError) - .finally(() => { - this.#callbacks.delete(callback.id); - }); + callback.promise.catch(debugError).finally(() => { + this.#callbacks.delete(callback.id); + }); callback.reject(error as Error); throw error; } // Must only have sync code up until here. - return callback.promise.valueOrThrow().finally(() => { + return callback.promise.finally(() => { this.#callbacks.delete(callback.id); }); } @@ -148,8 +145,8 @@ export class Callback { return this.#id; } - get promise(): Deferred { - return this.#deferred; + get promise(): Promise { + return this.#deferred.valueOrThrow(); } get error(): ProtocolError {