MCPcopy Index your code
hub / github.com/angular-ui/ui-router / $TimeoutProvider

Function $TimeoutProvider

test/angular/1.6/angular.js:20770–20864  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

20768
20769/** @this */
20770function $TimeoutProvider() {
20771 this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler',
20772 function($rootScope, $browser, $q, $$q, $exceptionHandler) {
20773
20774 var deferreds = {};
20775
20776
20777 /**
20778 * @ngdoc service
20779 * @name $timeout
20780 *
20781 * @description
20782 * AngularJS's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
20783 * block and delegates any exceptions to
20784 * {@link ng.$exceptionHandler $exceptionHandler} service.
20785 *
20786 * The return value of calling `$timeout` is a promise, which will be resolved when
20787 * the delay has passed and the timeout function, if provided, is executed.
20788 *
20789 * To cancel a timeout request, call `$timeout.cancel(promise)`.
20790 *
20791 * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
20792 * synchronously flush the queue of deferred functions.
20793 *
20794 * If you only want a promise that will be resolved after some specified delay
20795 * then you can call `$timeout` without the `fn` function.
20796 *
20797 * @param {function()=} fn A function, whose execution should be delayed.
20798 * @param {number=} [delay=0] Delay in milliseconds.
20799 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
20800 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
20801 * @param {...*=} Pass additional parameters to the executed function.
20802 * @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
20803 * will be resolved with the return value of the `fn` function.
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 }

Callers

nothing calls this directly

Calls 1

markQExceptionHandledFunction · 0.70

Tested by

no test coverage detected