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

Function $TimeoutProvider

lib/test/angular/1.7.0/angular.js:20836–20940  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

20834
20835/** @this */
20836function $TimeoutProvider() {
20837 this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler',
20838 function($rootScope, $browser, $q, $$q, $exceptionHandler) {
20839
20840 var deferreds = {};
20841
20842
20843 /**
20844 * @ngdoc service
20845 * @name $timeout
20846 *
20847 * @description
20848 * AngularJS's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
20849 * block and delegates any exceptions to
20850 * {@link ng.$exceptionHandler $exceptionHandler} service.
20851 *
20852 * The return value of calling `$timeout` is a promise, which will be resolved when
20853 * the delay has passed and the timeout function, if provided, is executed.
20854 *
20855 * To cancel a timeout request, call `$timeout.cancel(promise)`.
20856 *
20857 * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
20858 * synchronously flush the queue of deferred functions.
20859 *
20860 * If you only want a promise that will be resolved after some specified delay
20861 * then you can call `$timeout` without the `fn` function.
20862 *
20863 * @param {function()=} fn A function, whose execution should be delayed.
20864 * @param {number=} [delay=0] Delay in milliseconds.
20865 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
20866 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
20867 * @param {...*=} Pass additional parameters to the executed function.
20868 * @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
20869 * will be resolved with the return value of the `fn` function.
20870 *
20871 */
20872 function timeout(fn, delay, invokeApply) {
20873 if (!isFunction(fn)) {
20874 invokeApply = delay;
20875 delay = fn;
20876 fn = noop;
20877 }
20878
20879 var args = sliceArgs(arguments, 3),
20880 skipApply = (isDefined(invokeApply) && !invokeApply),
20881 deferred = (skipApply ? $$q : $q).defer(),
20882 promise = deferred.promise,
20883 timeoutId;
20884
20885 timeoutId = $browser.defer(function() {
20886 try {
20887 deferred.resolve(fn.apply(null, args));
20888 } catch (e) {
20889 deferred.reject(e);
20890 $exceptionHandler(e);
20891 } finally {
20892 delete deferreds[promise.$$timeoutId];
20893 }

Callers

nothing calls this directly

Calls 1

markQExceptionHandledFunction · 0.70

Tested by

no test coverage detected