MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / $TimeoutProvider

Function $TimeoutProvider

lib/test/angular/1.6.7/angular.js:20494–20588  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

20492
20493/** @this */
20494function $TimeoutProvider() {
20495 this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler',
20496 function($rootScope, $browser, $q, $$q, $exceptionHandler) {
20497
20498 var deferreds = {};
20499
20500
20501 /**
20502 * @ngdoc service
20503 * @name $timeout
20504 *
20505 * @description
20506 * Angular's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
20507 * block and delegates any exceptions to
20508 * {@link ng.$exceptionHandler $exceptionHandler} service.
20509 *
20510 * The return value of calling `$timeout` is a promise, which will be resolved when
20511 * the delay has passed and the timeout function, if provided, is executed.
20512 *
20513 * To cancel a timeout request, call `$timeout.cancel(promise)`.
20514 *
20515 * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
20516 * synchronously flush the queue of deferred functions.
20517 *
20518 * If you only want a promise that will be resolved after some specified delay
20519 * then you can call `$timeout` without the `fn` function.
20520 *
20521 * @param {function()=} fn A function, whose execution should be delayed.
20522 * @param {number=} [delay=0] Delay in milliseconds.
20523 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
20524 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
20525 * @param {...*=} Pass additional parameters to the executed function.
20526 * @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
20527 * will be resolved with the return value of the `fn` function.
20528 *
20529 */
20530 function timeout(fn, delay, invokeApply) {
20531 if (!isFunction(fn)) {
20532 invokeApply = delay;
20533 delay = fn;
20534 fn = noop;
20535 }
20536
20537 var args = sliceArgs(arguments, 3),
20538 skipApply = (isDefined(invokeApply) && !invokeApply),
20539 deferred = (skipApply ? $$q : $q).defer(),
20540 promise = deferred.promise,
20541 timeoutId;
20542
20543 timeoutId = $browser.defer(function() {
20544 try {
20545 deferred.resolve(fn.apply(null, args));
20546 } catch (e) {
20547 deferred.reject(e);
20548 $exceptionHandler(e);
20549 } finally {
20550 delete deferreds[promise.$$timeoutId];
20551 }

Callers

nothing calls this directly

Calls 1

markQExceptionHandledFunction · 0.70

Tested by

no test coverage detected