Skip to content

Commit 262c6fe

Browse files
committed
chore: addressing minor comments
1 parent 6445e26 commit 262c6fe

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

packages/sdk/browser/src/BrowserClient.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,17 @@ class BrowserClientImpl extends LDClientImpl {
240240
): Promise<LDWaitForInitializationResult> {
241241
const timeout = options?.timeout ?? 5;
242242

243-
// An initialization promise is only created if someone is going to use that promise.
244-
// If we always created an initialization promise, and there was no call waitForInitialization
245-
// by the time the promise was rejected, then that would result in an unhandled promise
246-
// rejection.
243+
// If initialization has already completed (successfully or failed), return the result immediately.
244+
if (this._initializeResult) {
245+
return Promise.resolve(this._initializeResult);
246+
}
247247

248-
// It waitForInitialization was previously called, then we can use that promise even if it has
249-
// been resolved or rejected.
248+
// It waitForInitialization was previously called, then return the promise with a timeout.
249+
// This condition should only be triggered if waitForInitialization was called multiple times.
250250
if (this._initializedPromise) {
251251
return this._promiseWithTimeout(this._initializedPromise, timeout);
252252
}
253253

254-
// If initialization has already completed (successfully or failed), return the result immediately
255-
if (this._initializeResult) {
256-
return Promise.resolve(this._initializeResult);
257-
}
258-
259254
if (!this._initializedPromise) {
260255
this._initializedPromise = new Promise((resolve) => {
261256
this._initResolve = resolve;

0 commit comments

Comments
 (0)