When making multiple change on a syncable object, multiple call to send are made and only the first callback of send will be called.
One way to work around this problem is to ensure only one call to change is made by Task of the EventLoop (by using setImmadiate for example). Or store the promise return by send to call the next send after the promise resolve and ignore all other send while a send is queued.
const s = syncable({
a: false,
b: false
});
s.subscribe((value, meta, hasUnsentChanges) => {
console.log(value, meta, hasUnsentChanges);
if (hasUnsentChanges) {
s.send((changes) => {
console.log(changes);
return Promise.resolve()
})
}
});
s.change(new JSONPatch().add('/a', true));
s.change(new JSONPatch().add('/b', true));
s.change(new JSONPatch().add('/a', false));
When making multiple change on a syncable object, multiple call to
sendare made and only the first callback ofsendwill be called.One way to work around this problem is to ensure only one call to
changeis made by Task of the EventLoop (by usingsetImmadiatefor example). Or store the promise return bysendto call the nextsendafter the promise resolve and ignore all othersendwhile asendis queued.