* @ngdoc service * @name $timeout * * @description * Angular'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 retu
(fn, delay, invokeApply)
| 17838 | * |
| 17839 | */ |
| 17840 | function timeout(fn, delay, invokeApply) { |
| 17841 | if (!isFunction(fn)) { |
| 17842 | invokeApply = delay; |
| 17843 | delay = fn; |
| 17844 | fn = noop; |
| 17845 | } |
| 17846 | |
| 17847 | var args = sliceArgs(arguments, 3), |
| 17848 | skipApply = (isDefined(invokeApply) && !invokeApply), |
| 17849 | deferred = (skipApply ? $$q : $q).defer(), |
| 17850 | promise = deferred.promise, |
| 17851 | timeoutId; |
| 17852 | |
| 17853 | timeoutId = $browser.defer(function() { |
| 17854 | try { |
| 17855 | deferred.resolve(fn.apply(null, args)); |
| 17856 | } catch (e) { |
| 17857 | deferred.reject(e); |
| 17858 | $exceptionHandler(e); |
| 17859 | } |
| 17860 | finally { |
| 17861 | delete deferreds[promise.$$timeoutId]; |
| 17862 | } |
| 17863 | |
| 17864 | if (!skipApply) $rootScope.$apply(); |
| 17865 | }, delay); |
| 17866 | |
| 17867 | promise.$$timeoutId = timeoutId; |
| 17868 | deferreds[timeoutId] = deferred; |
| 17869 | |
| 17870 | return promise; |
| 17871 | } |
| 17872 | |
| 17873 | |
| 17874 | /** |
nothing calls this directly
no test coverage detected