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 authored and sfc-gh-pmotacki committed Nov 21, 2024
1 parent c4e6edb commit d40a3f4
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 d40a3f4

Please sign in to comment.