Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions package-mixins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { NativeEventEmitter } from "react-native";
import log from "./logging";

// Reporting this event is important, but avoid blocking install()/restartApp() indefinitely
// on a stalled network request.
const REPORT_STATUS_DOWNLOAD_TIMEOUT_MS = 5000;

async function withTimeout(promise, timeoutMs) {
let timer;
const timeout = new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error(`Timed out after ${timeoutMs}ms`)), timeoutMs);
});

try {
return await Promise.race([promise, timeout]);
} finally {
clearTimeout(timer);
}
}

// This function is used to augment remote and local
// package objects with additional functionality/properties
// beyond what is included in the metadata sent by the server.
Expand Down Expand Up @@ -31,10 +48,11 @@ module.exports = (NativeCodePush) => {
const downloadedPackage = await NativeCodePush.downloadUpdate(updatePackageCopy, !!downloadProgressCallback);

if (reportStatusDownload) {
reportStatusDownload(this)
.catch((err) => {
try {
await withTimeout(reportStatusDownload(this), REPORT_STATUS_DOWNLOAD_TIMEOUT_MS);
} catch (err) {
log(`Report download status failed: ${err}`);
});
}
Comment on lines 50 to +55

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

return { ...downloadedPackage, ...local };
Expand Down Expand Up @@ -65,4 +83,4 @@ module.exports = (NativeCodePush) => {
};

return { local, remote };
};
};
3 changes: 2 additions & 1 deletion src/acquisition-sdk/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export class AcquisitionManager {
});
}

// Note: deployedPackage and status are null when reporting a "binary update" (i.e. the app was updated through the app store, not CodePush)
public reportStatusDeploy(deployedPackage?: Package, status?: string, previousLabelOrAppVersion?: string, previousDeploymentKey?: string, callback?: Callback<void>): void {
if (AcquisitionManager._apiCallsDisabled) {
console.log(`[CodePush] Api calls are disabled, skipping API call`);
Expand Down Expand Up @@ -289,4 +290,4 @@ function queryStringify(object: Object): string {
}

return queryString;
}
}