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

Figure out a strategy to fire less (network) requests if the sync period (outOfDateAfter) is extremely fast #7

Open
superKalo opened this issue Sep 29, 2017 · 0 comments
Assignees

Comments

@superKalo
Copy link
Owner

superKalo commented Sep 29, 2017

Basically, in case the request response is not received yet, do not issue a new (network) request. Wait for the one which is still pending.

Here's a test for this (kind of extreme) use-case:

it('Should wait if there is a Promise pending and should NOT fire another one', done => {
    let networkRequestsCount = 0;

    const repo = new SuperRepo({
        storage: 'LOCAL_VARIABLE',
        name: 'test',
        outOfDateAfter: 1000, // 1 second
        request: () => {
            networkRequestsCount++;

            return new Promise(resolve => {
                clock.tick(10 * 1000);
                resolve('whatever');
            });
        }
    });

    repo.initSyncer().then( () => {
        expect(networkRequestsCount).to.equal(1);

        clock.tick(15 * 1000);
        expect(networkRequestsCount).to.equal(2);
    }).then(done, done);
});
@superKalo superKalo self-assigned this Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant