Tuesday, March 28, 2006

Prototype PeriodicalExecuter.stop()

James Gregory has a written a simple extension for the PeriodicalExecutor class of prototype.js to add a stop() method to it.

PeriodicalExecuter.prototype.registerCallback = function() {
this
.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
}

PeriodicalExecuter.prototype.stop =
function() {
clearInterval(
this.intervalID);
}
All it does is take the current registerCallback function (which creates the actual timer) and stores its returned interval ID which we then use in the new stop function with the native clearInterval method.

Complete article is here: http://www.metalmadness.co.uk/Blog/archive/2006/01/09/801.aspx

2 comments:

Anonymous said...

Thanks for the link Mandy, glad you think it's worth people taking a look!

Unknown said...

good work Mandy, Nice tip, but for some reason the stop function still dint work even after this. But i found it successfull to call the clearInterval(this.IntervalId); instead of pe.stop();

when i did that it worked for me.

Thanks for the nice tip.