Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send callback missed when multiple change are made #8

Open
11mad11 opened this issue Dec 15, 2023 · 0 comments
Open

send callback missed when multiple change are made #8

11mad11 opened this issue Dec 15, 2023 · 0 comments

Comments

@11mad11
Copy link

11mad11 commented Dec 15, 2023

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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant