Skip to content

send callback missed when multiple change are made #8

@11mad11

Description

@11mad11

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions