MCPcopy Create free account
hub / github.com/OpenReservation/OpenReservation / interval

Function interval

OpenReservation/wwwroot/Scripts/angular.js:12334–12375  ·  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

(fn, delay, count, invokeApply)

Source from the content-addressed store, hash-verified

12332 * </example>
12333 */
12334 function interval(fn, delay, count, invokeApply) {
12335 var hasParams = arguments.length > 4,
12336 args = hasParams ? sliceArgs(arguments, 4) : [],
12337 setInterval = $window.setInterval,
12338 clearInterval = $window.clearInterval,
12339 iteration = 0,
12340 skipApply = (isDefined(invokeApply) && !invokeApply),
12341 deferred = (skipApply ? $$q : $q).defer(),
12342 promise = deferred.promise;
12343
12344 count = isDefined(count) ? count : 0;
12345
12346 promise.$$intervalId = setInterval(function tick() {
12347 if (skipApply) {
12348 $browser.defer(callback);
12349 } else {
12350 $rootScope.$evalAsync(callback);
12351 }
12352 deferred.notify(iteration++);
12353
12354 if (count > 0 && iteration >= count) {
12355 deferred.resolve(iteration);
12356 clearInterval(promise.$$intervalId);
12357 delete intervals[promise.$$intervalId];
12358 }
12359
12360 if (!skipApply) $rootScope.$apply();
12361 },
12362 delay);
12363
12364 intervals[promise.$$intervalId] = deferred;
12365
12366 return promise;
12367
12368 function callback() {
12369 if (!hasParams) {
12370 fn(iteration);
12371 } else {
12372 fn.apply(null, args);
12373 }
12374 }
12375 }
12376
12377 /**
12378 * @ngdoc method

Callers

nothing calls this directly

Calls 2

sliceArgsFunction · 0.85
isDefinedFunction · 0.85

Tested by

no test coverage detected