mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 06:45:49 +01:00
new mechanism to wait for sync after interaction with backend in Script API using api.waitForMaxKnownSyncId()
This commit is contained in:
@@ -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
|
||||
};
|
||||
Reference in New Issue
Block a user