* @ngdoc function * @name ng.$timeout * @requires $browser * * @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 se
(fn, delay, invokeApply)
| 9463 | * promise will be resolved with is the return value of the `fn` function. |
| 9464 | */ |
| 9465 | function timeout(fn, delay, invokeApply) { |
| 9466 | var deferred = $q.defer(), |
| 9467 | promise = deferred.promise, |
| 9468 | skipApply = (isDefined(invokeApply) && !invokeApply), |
| 9469 | timeoutId, cleanup; |
| 9470 | |
| 9471 | timeoutId = $browser.defer(function() { |
| 9472 | try { |
| 9473 | deferred.resolve(fn()); |
| 9474 | } catch(e) { |
| 9475 | deferred.reject(e); |
| 9476 | $exceptionHandler(e); |
| 9477 | } |
| 9478 | |
| 9479 | if (!skipApply) $rootScope.$apply(); |
| 9480 | }, delay); |
| 9481 | |
| 9482 | cleanup = function() { |
| 9483 | delete deferreds[promise.$$timeoutId]; |
| 9484 | }; |
| 9485 | |
| 9486 | promise.$$timeoutId = timeoutId; |
| 9487 | deferreds[timeoutId] = deferred; |
| 9488 | promise.then(cleanup, cleanup); |
| 9489 | |
| 9490 | return promise; |
| 9491 | } |
| 9492 | |
| 9493 | |
| 9494 | /** |
nothing calls this directly
no test coverage detected