Angular interval service which doubles the delay with every iteration
bower install ng-progressive-interval --save
You can use it similarly like angular's built-in $interval
service. Inject it as dependency and pass a function to it.
angular.module("myApp", ["retoheusser.ng-progressive-interval"])
.controller("myAppCtrl", function (progressiveInterval) {
progressiveInterval(function () {
// this gets executed after 1s, then after 2s, then 4s, then 8s and so on...
}, 1000);
});
var cancelInterval = progressiveInterval(fn, initialDelay, maxDelay, maxIterations)
- Parameters:
fn
: Function to executeinitialDelay
: Delay in ms, increases by factor 2 in every iterationmaxDelay
: If initialDelay exceeds maxDelay, use this value instead. It remains constant.maxIterations
:fn
will not be executed more than this value. Inifite iterations if undefined or 0.
- Returns:
function
: a callable function without parameters to cancel the interval.