Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 2177a11

Browse files
committed
feedback
1 parent 360fb33 commit 2177a11

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

CodePush.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,20 @@ function log(message) {
139139
console.log(`[CodePush] ${message}`)
140140
}
141141

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() {
143156
await NativeCodePush.notifyApplicationReady();
144157
const statusReport = await NativeCodePush.getNewStatusReport();
145158
if (statusReport) {
@@ -170,15 +183,26 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) {
170183
if (testNativeBridge) NativeCodePush = testNativeBridge;
171184
}
172185

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.
175188
const sync = (() => {
176-
let syncPromiseChain = Promise.resolve();
189+
let syncInProgress = false;
190+
const setSyncCompleted = () => { syncInProgress = false; };
191+
177192
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;
182206
};
183207
})();
184208

@@ -350,6 +374,7 @@ const CodePush = {
350374
UP_TO_DATE: 4, // The running app is up-to-date
351375
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
352376
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.
353378
UNKNOWN_ERROR: -1
354379
},
355380
DEFAULT_UPDATE_DIALOG: {

CodePush.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
506506
RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve
507507
rejecter:(RCTPromiseRejectBlock)reject)
508508
{
509-
// We only mark a pending update as succeeded only if it has been booted up
510-
// successfully, during which `_isFirstRunAfterUpdate` is set to true.
511-
if (_isFirstRunAfterUpdate) {
512-
[CodePush removePendingUpdate];
513-
}
514-
509+
[CodePush removePendingUpdate];
515510
resolve(nil);
516511
}
517512

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,7 @@ public void isFirstRun(String packageHash, Promise promise) {
539539

540540
@ReactMethod
541541
public void notifyApplicationReady(Promise promise) {
542-
// We only mark a pending update as succeeded only if it has been booted up
543-
// successfully, during which `didUpdate` is set to true.
544-
if (didUpdate) {
545-
removePendingUpdate();
546-
}
547-
542+
removePendingUpdate();
548543
promise.resolve("");
549544
}
550545

0 commit comments

Comments
 (0)