From 8d4ab19026f5c335906773bdca9009db0e76639f Mon Sep 17 00:00:00 2001 From: Adrian Cooney Date: Thu, 7 Nov 2024 14:00:27 +0000 Subject: [PATCH] Clear timeout if the brower action promise resolves before timeout --- lib/authentication/auth_web.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/authentication/auth_web.js b/lib/authentication/auth_web.js index 4055422b4..17ea8da98 100644 --- a/lib/authentication/auth_web.js +++ b/lib/authentication/auth_web.js @@ -177,12 +177,15 @@ function AuthWeb(connectionConfig, httpClient, webbrowser) { } const withBrowserActionTimeout = (millis, promise) => { + let timeoutId; + const timeout = new Promise((resolve, reject) => - setTimeout( + timeoutId = setTimeout( () => reject(`Browser action timed out after ${browserActionTimeout} ms.`), millis)); + return Promise.race([ - promise, + promise.finally(() => clearTimeout(timeoutId)), timeout ]); };