@@ -139,7 +139,20 @@ function log(message) {
139
139
console . log ( `[CodePush] ${ message } ` )
140
140
}
141
141
142
- async function notifyApplicationReady ( ) {
142
+ // This ensures that notifyApplicationReadyInternal is only called once
143
+ // in the lifetime of this module instance.
144
+ const notifyApplicationReady = ( ( ) => {
145
+ let notifyApplicationReadyPromise ;
146
+ return ( ) => {
147
+ if ( ! notifyApplicationReadyPromise ) {
148
+ notifyApplicationReadyPromise = notifyApplicationReadyInternal ( ) ;
149
+ }
150
+
151
+ return notifyApplicationReadyPromise ;
152
+ } ;
153
+ } ) ( ) ;
154
+
155
+ async function notifyApplicationReadyInternal ( ) {
143
156
await NativeCodePush . notifyApplicationReady ( ) ;
144
157
const statusReport = await NativeCodePush . getNewStatusReport ( ) ;
145
158
if ( statusReport ) {
@@ -170,15 +183,26 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
170
183
if ( testNativeBridge ) NativeCodePush = testNativeBridge ;
171
184
}
172
185
173
- // This function allows calls to syncInternal to be chained on to each other so that they do not
174
- // interleave in the event that sync() is called multiple times .
186
+ // This function allows only one syncInternal operation to proceed at any given time.
187
+ // Parallel calls to sync() while one is ongoing yields CodePush.SyncStatus.SYNC_IN_PROGRESS .
175
188
const sync = ( ( ) => {
176
- let syncPromiseChain = Promise . resolve ( ) ;
189
+ let syncInProgress = false ;
190
+ const setSyncCompleted = ( ) => { syncInProgress = false ; } ;
191
+
177
192
return ( options = { } , syncStatusChangeCallback , downloadProgressCallback ) => {
178
- syncPromiseChain = syncPromiseChain
179
- . catch ( ( ) => { } )
180
- . then ( ( ) => syncInternal ( options , syncStatusChangeCallback , downloadProgressCallback ) ) ;
181
- return syncPromiseChain ;
193
+ if ( syncInProgress ) {
194
+ syncStatusChangeCallback ( CodePush . SyncStatus . SYNC_IN_PROGRESS ) ;
195
+ return Promise . resolve ( CodePush . SyncStatus . SYNC_IN_PROGRESS ) ;
196
+ }
197
+
198
+ syncInProgress = true ;
199
+ const syncInternalPromise = syncInternal ( options , syncStatusChangeCallback , downloadProgressCallback ) ;
200
+ syncInternalPromise
201
+ . then ( setSyncCompleted )
202
+ . catch ( setSyncCompleted )
203
+ . done ( ) ;
204
+
205
+ return syncInternalPromise ;
182
206
} ;
183
207
} ) ( ) ;
184
208
@@ -350,6 +374,7 @@ const CodePush = {
350
374
UP_TO_DATE : 4 , // The running app is up-to-date
351
375
UPDATE_IGNORED : 5 , // The app had an optional update and the end-user chose to ignore it
352
376
UPDATE_INSTALLED : 6 , // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
377
+ SYNC_IN_PROGRESS : 7 , // There is an ongoing "sync" operation in progress.
353
378
UNKNOWN_ERROR : - 1
354
379
} ,
355
380
DEFAULT_UPDATE_DIALOG : {
0 commit comments