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

Function $TimeoutProvider

lib/test/angular/1.8.0/angular.js:21610–21714  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

21608
21609/** @this */
21610function $TimeoutProvider() {
21611 this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler',
21612 function($rootScope, $browser, $q, $$q, $exceptionHandler) {
21613
21614 var deferreds = {};
21615
21616
21617 /**
21618 * @ngdoc service
21619 * @name $timeout
21620 *
21621 * @description
21622 * AngularJS's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
21623 * block and delegates any exceptions to
21624 * {@link ng.$exceptionHandler $exceptionHandler} service.
21625 *
21626 * The return value of calling `$timeout` is a promise, which will be resolved when
21627 * the delay has passed and the timeout function, if provided, is executed.
21628 *
21629 * To cancel a timeout request, call `$timeout.cancel(promise)`.
21630 *
21631 * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
21632 * synchronously flush the queue of deferred functions.
21633 *
21634 * If you only want a promise that will be resolved after some specified delay
21635 * then you can call `$timeout` without the `fn` function.
21636 *
21637 * @param {function()=} fn A function, whose execution should be delayed.
21638 * @param {number=} [delay=0] Delay in milliseconds.
21639 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
21640 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
21641 * @param {...*=} Pass additional parameters to the executed function.
21642 * @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
21643 * will be resolved with the return value of the `fn` function.
21644 *
21645 */
21646 function timeout(fn, delay, invokeApply) {
21647 if (!isFunction(fn)) {
21648 invokeApply = delay;
21649 delay = fn;
21650 fn = noop;
21651 }
21652
21653 var args = sliceArgs(arguments, 3),
21654 skipApply = (isDefined(invokeApply) && !invokeApply),
21655 deferred = (skipApply ? $$q : $q).defer(),
21656 promise = deferred.promise,
21657 timeoutId;
21658
21659 timeoutId = $browser.defer(function() {
21660 try {
21661 deferred.resolve(fn.apply(null, args));
21662 } catch (e) {
21663 deferred.reject(e);
21664 $exceptionHandler(e);
21665 } finally {
21666 delete deferreds[promise.$$timeoutId];
21667 }

Callers

nothing calls this directly

Calls 1

markQExceptionHandledFunction · 0.70

Tested by

no test coverage detected