@@ -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