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

@@ -21,6 +21,10 @@ async function addEntitySync(entityName, entityId, sourceId) {
setTimeout(() => require('./ws').sendPingToAllClients(), 50);
}
function getMaxSyncId() {
return syncs.length === 0 ? 0 : syncs[syncs.length - 1].id;
}
function getEntitySyncsNewerThan(syncId) {
return syncs.filter(s => s.id > syncId);
}
@@ -96,5 +100,6 @@ module.exports = {
addApiTokenSync: async (apiTokenId, sourceId) => await addEntitySync("api_tokens", apiTokenId, sourceId),
addEntitySync,
fillAllSyncRows,
getEntitySyncsNewerThan
getEntitySyncsNewerThan,
getMaxSyncId
};