From 63ff0835922516a8d56a78aa60445b0599fff95e Mon Sep 17 00:00:00 2001 From: "EchoLayer Bot (Stag)" Date: Wed, 13 Mar 2024 18:20:31 +0000 Subject: [PATCH] Removed the TODO comment and added explanations to the Promise.race block to describe how it works. --- codex-vscode/src/services/oauth.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codex-vscode/src/services/oauth.service.ts b/codex-vscode/src/services/oauth.service.ts index a1e1e68a..72648dfb 100644 --- a/codex-vscode/src/services/oauth.service.ts +++ b/codex-vscode/src/services/oauth.service.ts @@ -31,11 +31,14 @@ export class OAuthService implements IOAuthService { ); } + // The Promise.race method is used here to race two promises against each other: + // 1. OAuthService.codeExchangePromise.promise - This promise resolves when the user completes the authorization process. + // 2. A timeout promise that rejects after 60 seconds, indicating the user did not complete the login in time. + // The first promise to settle (either resolve or reject) will determine the outcome of the authenticate method. return Promise.race([ OAuthService.codeExchangePromise.promise, new Promise((_, reject) => setTimeout(() => { - // TODO we should make this alot simpler this.clearCodeExchangePromise(); reject({ errorType: "cancelled", @@ -46,6 +49,7 @@ export class OAuthService implements IOAuthService { ]); } + // postAuthorization returns a function that is called from the promiseFromEvent function when the event is fired private postAuthorization: () => PromiseAdapter = () =>