new mechanism to wait for sync after interaction with backend in Script API using api.waitForMaxKnownSyncId()

This commit is contained in:
zadam
2019-12-09 23:07:45 +01:00
parent 1e123f2390
commit 6f32d6fabe
7 changed files with 89 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import utils from './utils.js';
import toastService from "./toast.js";
import server from "./server.js";
const $outstandingSyncsCount = $("#outstanding-syncs-count");
@@ -71,8 +72,6 @@ async function handleMessage(event) {
// finish and set to null to signal somebody else can pick it up
consumeQueuePromise = null;
}
checkSyncIdListeners();
}
else if (message.type === 'sync-hash-check-failed') {
toastService.showError("Sync check failed!", 60000);
@@ -98,6 +97,10 @@ function waitForSyncId(desiredSyncId) {
});
}
function waitForMaxKnownSyncId() {
return waitForSyncId(server.getMaxKnownSyncId());
}
function checkSyncIdListeners() {
syncIdReachedListeners
.filter(l => l.desiredSyncId <= lastProcessedSyncId)
@@ -129,6 +132,8 @@ async function consumeSyncData() {
lastProcessedSyncId = Math.max(lastProcessedSyncId, allSyncData[allSyncData.length - 1].id);
}
checkSyncIdListeners();
}
function connectWebSocket() {
@@ -193,5 +198,6 @@ export default {
subscribeToMessages,
subscribeToAllSyncMessages,
subscribeToOutsideSyncMessages,
waitForSyncId
waitForSyncId,
waitForMaxKnownSyncId
};