* @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)
| 20804 | * |
| 20805 | */ |
| 20806 | function timeout(fn, delay, invokeApply) { |
| 20807 | if (!isFunction(fn)) { |
| 20808 | invokeApply = delay; |
| 20809 | delay = fn; |
| 20810 | fn = noop; |
| 20811 | } |
| 20812 | |
| 20813 | var args = sliceArgs(arguments, 3), |
| 20814 | skipApply = (isDefined(invokeApply) && !invokeApply), |
| 20815 | deferred = (skipApply ? $$q : $q).defer(), |
| 20816 | promise = deferred.promise, |
| 20817 | timeoutId; |
| 20818 | |
| 20819 | timeoutId = $browser.defer(function() { |
| 20820 | try { |
| 20821 | deferred.resolve(fn.apply(null, args)); |
| 20822 | } catch (e) { |
| 20823 | deferred.reject(e); |
| 20824 | $exceptionHandler(e); |
| 20825 | } finally { |
| 20826 | delete deferreds[promise.$$timeoutId]; |
| 20827 | } |
| 20828 | |
| 20829 | if (!skipApply) $rootScope.$apply(); |
| 20830 | }, delay); |
| 20831 | |
| 20832 | promise.$$timeoutId = timeoutId; |
| 20833 | deferreds[timeoutId] = deferred; |
| 20834 | |
| 20835 | return promise; |
| 20836 | } |
| 20837 | |
| 20838 | |
| 20839 | /** |
nothing calls this directly
no test coverage detected