Restart the poller...
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)
Thanks for the catch. Pretty nasty bug.
Just tested in my env and it works as expected. Thanks