blob: b5dc8844075055079948217f590c1e456dd45e0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
'use strict';
/**
* @ngdoc function
* @name angular.module.ng.$defer
* @deprecated Made obsolete by $timeout service. Please migrate your code. This service will be
* removed with 1.0 final.
* @requires $browser
*
* @description
* Delegates to {@link angular.module.ng.$browser#defer $browser.defer}, but wraps the `fn` function
* into a try/catch block and delegates any exceptions to
* {@link angular.module.ng.$exceptionHandler $exceptionHandler} service.
*
* In tests you can use `$browser.defer.flush()` to flush the queue of deferred functions.
*
* @param {function()} fn A function, who's execution should be deferred.
* @param {number=} [delay=0] of milliseconds to defer the function execution.
* @returns {*} DeferId that can be used to cancel the task via `$defer.cancel()`.
*/
/**
* @ngdoc function
* @name angular.module.ng.$defer#cancel
* @methodOf angular.module.ng.$defer
*
* @description
* Cancels a defered task identified with `deferId`.
*
* @param {*} deferId Token returned by the `$defer` function.
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfuly canceled.
*/
function $DeferProvider(){
this.$get = ['$rootScope', '$browser', '$log', function($rootScope, $browser, $log) {
$log.warn('$defer service has been deprecated, migrate to $timeout');
function defer(fn, delay) {
return $browser.defer(function() {
$rootScope.$apply(fn);
}, delay);
}
defer.cancel = function(deferId) {
return $browser.defer.cancel(deferId);
};
return defer;
}];
}
|