MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / interval

Function interval

code/songhop/www/lib/angular/angular.js:10323–10351  ·  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

10321 * </example>
10322 */
10323 function interval(fn, delay, count, invokeApply) {
10324 var setInterval = $window.setInterval,
10325 clearInterval = $window.clearInterval,
10326 iteration = 0,
10327 skipApply = (isDefined(invokeApply) && !invokeApply),
10328 deferred = (skipApply ? $$q : $q).defer(),
10329 promise = deferred.promise;
10330
10331 count = isDefined(count) ? count : 0;
10332
10333 promise.then(null, null, fn);
10334
10335 promise.$$intervalId = setInterval(function tick() {
10336 deferred.notify(iteration++);
10337
10338 if (count > 0 && iteration >= count) {
10339 deferred.resolve(iteration);
10340 clearInterval(promise.$$intervalId);
10341 delete intervals[promise.$$intervalId];
10342 }
10343
10344 if (!skipApply) $rootScope.$apply();
10345
10346 }, delay);
10347
10348 intervals[promise.$$intervalId] = deferred;
10349
10350 return promise;
10351 }
10352
10353
10354 /**

Callers

nothing calls this directly

Calls 1

isDefinedFunction · 0.70

Tested by

no test coverage detected