Skip to content

Commit

Permalink
Clear timeout if the brower action promise resolves before timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancooney committed Nov 7, 2024
1 parent 00e3b95 commit 052936e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/authentication/auth_web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
};
Expand Down

0 comments on commit 052936e

Please sign in to comment.