Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Restart the poller... #9

Closed
cardinal27513 opened this issue May 17, 2012 · 2 comments
Closed

Restart the poller... #9

cardinal27513 opened this issue May 17, 2012 · 2 comments
Assignees

Comments

@cardinal27513
Copy link

I'm having issue with the "start()" which is suppose to stop() and start() so that the new options can be updated as you suggested.

I simplified my code to run some experiment and here is what I did... Essentially, I start the poller and then after 10 sec re-start the poller (suppose to the change the time out, but just keep it the same for now).... do the restart twice...

var Polling = Polling || {};

Polling.model = new Backbone.Model();
Polling.model.url =  'url.example.com';

Polling.poller = PollingManager.getPoller(Polling.model, {delay: 10000, fetch: function () {console.log('pre-fetch @' +  new Date());} }).start();

Polling.restart_count = 0;

Polling.restart_poller = function () {
    Polling.restart_count ++;
    console.log ("Restart the poller: count = " + Polling.restart_count );

    Polling.poller = PollingManager.getPoller(Polling.model, {delay: 10000}).start();
    if (Polling.restart_count >= 2) {
        console.log ("No more restart the poller");
        window.clearTimeout(Polling.timer  );
    }   
};

Polling.timer  = window.setInterval( 'Polling.restart_poller()', 10000);

The expected behavior is that after each re-start, the poller should just continue to poll at every 10 sec.. since I did not change anything....
But the result is different, after the 1st re-start, I start to see that there are two back-2-back pollings every 10 sec
After the 2nd re-start, there are three back-to-back polls for every 10 sec..

Seems that the original scheduled pollings are not cancelled but just keep adding to it...

Here is what I see from the console log

pre-fetch @Wed May 16 2012 23:51:58 GMT-0400 (Eastern Daylight Time)

<< These two lines I can understand since the original poll finished and new one starts also>>>
Restart the poller: count = 1
pre-fetch @Wed May 16 2012 23:52:08 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:09 GMT-0400 (Eastern Daylight Time)

<< We should see only two lines; but there are three!!>>>
Restart the poller: count = 2
pre-fetch @Wed May 16 2012 23:52:18 GMT-0400 (Eastern Daylight Time)
No more restart the poller
pre-fetch @Wed May 16 2012 23:52:18 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:19 GMT-0400 (Eastern Daylight Time)

<< We should see only one poll but there are three!!>>>
pre-fetch @Wed May 16 2012 23:52:28 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:29 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:29 GMT-0400 (Eastern Daylight Time)

<< We should see only one poll but there are three!!>>>
pre-fetch @Wed May 16 2012 23:52:39 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:39 GMT-0400 (Eastern Daylight Time)
pre-fetch @Wed May 16 2012 23:52:39 GMT-0400 (Eastern Daylight Time)

@ghost ghost assigned uzikilon May 17, 2012
uzikilon added a commit that referenced this issue May 17, 2012
@uzikilon
Copy link
Owner

Thanks for the catch. Pretty nasty bug.

@cardinal27513
Copy link
Author

Just tested in my env and it works as expected.
Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants