A jQuery class to manage a loop with some interval.
I want set a loop with some interval.
Sometimes, I want to stop the loop or change the interval.
I explanation interval loop manager by setting a loop of the following function.
function yourFunction() {
// some process
}
In case you want to set loop with 5 seconds interval.
var managedLoop =
new IntervalLoopManager(
yoruFunction,
{ interval: 5000 }
)
or
var managedLoop = new IntervalLoopManager( yourFunction )
managedLoop.start({ interval: 5000 })
managedLoop.stop()
managedLoop.restart()
or
managedLoop.start()
Ways to change the interval to 7 seconds.
In case you want to change it as soon as possible.
managedLoop.restart({ interval: 7000 })
In case you allow current loop to finish.
managedLoop.assignValues({ interval: 7000 })
if ( managedLoop.isPresent() ) {
console.log('Looping.')
} else {
console.log('No loop.')
}
MIT.
http://stackoverflow.com/questions/1280263/changing-the-interval-of-setinterval-while-its-running