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

Function timeout

test/angular/1.4/angular.js:18253–18284  ·  view source on GitHub ↗

* @ngdoc service * @name $timeout * * @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 service. * * The retu

(fn, delay, invokeApply)

Source from the content-addressed store, hash-verified

18251 *
18252 */
18253 function timeout(fn, delay, invokeApply) {
18254 if (!isFunction(fn)) {
18255 invokeApply = delay;
18256 delay = fn;
18257 fn = noop;
18258 }
18259
18260 var args = sliceArgs(arguments, 3),
18261 skipApply = (isDefined(invokeApply) && !invokeApply),
18262 deferred = (skipApply ? $$q : $q).defer(),
18263 promise = deferred.promise,
18264 timeoutId;
18265
18266 timeoutId = $browser.defer(function() {
18267 try {
18268 deferred.resolve(fn.apply(null, args));
18269 } catch (e) {
18270 deferred.reject(e);
18271 $exceptionHandler(e);
18272 }
18273 finally {
18274 delete deferreds[promise.$$timeoutId];
18275 }
18276
18277 if (!skipApply) $rootScope.$apply();
18278 }, delay);
18279
18280 promise.$$timeoutId = timeoutId;
18281 deferreds[timeoutId] = deferred;
18282
18283 return promise;
18284 }
18285
18286
18287 /**

Callers

nothing calls this directly

Calls 3

isFunctionFunction · 0.70
sliceArgsFunction · 0.70
isDefinedFunction · 0.70

Tested by

no test coverage detected