add time limit to frontend update

This commit is contained in:
zadam 2020-06-11 00:13:56 +02:00
parent 910bda860c
commit d09b021487
2 changed files with 22 additions and 3 deletions

View File

@ -316,6 +316,24 @@ function dynamicRequire(moduleName) {
}
}
function timeLimit(cb, limitMs) {
return new Promise((res, rej) => {
let resolved = false;
cb().then(() => {
resolved = true;
res();
});
setTimeout(() => {
if (!resolved) {
rej('Process exceeded time limit ' + limitMs);
}
}, limitMs);
});
}
export default {
reloadApp,
parseDate,
@ -355,5 +373,6 @@ export default {
normalizeShortcut,
copySelectionToClipboard,
isCKEditorInitialized,
dynamicRequire
};
dynamicRequire,
timeLimit
};

View File

@ -157,7 +157,7 @@ async function consumeSyncData() {
const nonProcessedSyncRows = allSyncRows.filter(sync => !processedSyncIds.has(sync.id));
try {
await processSyncRows(nonProcessedSyncRows);
await utils.timeLimit(async () => await processSyncRows(nonProcessedSyncRows), 5000);
}
catch (e) {
logError(`Encountered error ${e.message}: ${e.stack}, reloading frontend.`);