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

Function timeout

test/angular/1.7/angular.js:21581–21611  ·  view source on GitHub ↗

* @ngdoc service * @name $timeout * * @description * AngularJS's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch * block and delegates any exceptions to * ng.$exceptionHandler $exceptionHandler service. * * The return val

(fn, delay, invokeApply)

Source from the content-addressed store, hash-verified

21579 *
21580 */
21581 function timeout(fn, delay, invokeApply) {
21582 if (!isFunction(fn)) {
21583 invokeApply = delay;
21584 delay = fn;
21585 fn = noop;
21586 }
21587
21588 var args = sliceArgs(arguments, 3),
21589 skipApply = (isDefined(invokeApply) && !invokeApply),
21590 deferred = (skipApply ? $$q : $q).defer(),
21591 promise = deferred.promise,
21592 timeoutId;
21593
21594 timeoutId = $browser.defer(function() {
21595 try {
21596 deferred.resolve(fn.apply(null, args));
21597 } catch (e) {
21598 deferred.reject(e);
21599 $exceptionHandler(e);
21600 } finally {
21601 delete deferreds[promise.$$timeoutId];
21602 }
21603
21604 if (!skipApply) $rootScope.$apply();
21605 }, delay, '$timeout');
21606
21607 promise.$$timeoutId = timeoutId;
21608 deferreds[timeoutId] = deferred;
21609
21610 return promise;
21611 }
21612
21613
21614 /**

Callers

nothing calls this directly

Calls 3

isFunctionFunction · 0.70
sliceArgsFunction · 0.70
isDefinedFunction · 0.70

Tested by

no test coverage detected