MCPcopy
hub / github.com/angular-ui/ui-router / interval

Function interval

test/angular/1.3/angular.js:10434–10462  ·  view source on GitHub ↗

* @ngdoc service * @name $interval * * @description * Angular's wrapper for `window.setInterval`. The `fn` function is executed every `delay` * milliseconds. * * The return value of registering an interval function is a promise. This promise will be *

(fn, delay, count, invokeApply)

Source from the content-addressed store, hash-verified

10432 * </example>
10433 */
10434 function interval(fn, delay, count, invokeApply) {
10435 var setInterval = $window.setInterval,
10436 clearInterval = $window.clearInterval,
10437 iteration = 0,
10438 skipApply = (isDefined(invokeApply) && !invokeApply),
10439 deferred = (skipApply ? $$q : $q).defer(),
10440 promise = deferred.promise;
10441
10442 count = isDefined(count) ? count : 0;
10443
10444 promise.then(null, null, fn);
10445
10446 promise.$$intervalId = setInterval(function tick() {
10447 deferred.notify(iteration++);
10448
10449 if (count > 0 && iteration >= count) {
10450 deferred.resolve(iteration);
10451 clearInterval(promise.$$intervalId);
10452 delete intervals[promise.$$intervalId];
10453 }
10454
10455 if (!skipApply) $rootScope.$apply();
10456
10457 }, delay);
10458
10459 intervals[promise.$$intervalId] = deferred;
10460
10461 return promise;
10462 }
10463
10464
10465 /**

Callers

nothing calls this directly

Calls 1

isDefinedFunction · 0.70

Tested by

no test coverage detected