2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-02-15 06:12:45 +00:00
|
|
|
/**
|
2011-11-10 06:23:36 +00:00
|
|
|
* @ngdoc function
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.$defer
|
2012-05-23 06:05:26 +00:00
|
|
|
* @deprecated Made obsolete by $timeout service. Please migrate your code. This service will be
|
|
|
|
|
* removed with 1.0 final.
|
2011-02-15 06:12:45 +00:00
|
|
|
* @requires $browser
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2012-06-12 06:49:24 +00:00
|
|
|
* Delegates to {@link ng.$browser#defer $browser.defer}, but wraps the `fn` function
|
2011-02-15 06:12:45 +00:00
|
|
|
* into a try/catch block and delegates any exceptions to
|
2012-06-12 06:49:24 +00:00
|
|
|
* {@link ng.$exceptionHandler $exceptionHandler} service.
|
2011-02-15 06:12:45 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
2011-02-25 19:18:42 +00:00
|
|
|
* @param {number=} [delay=0] of milliseconds to defer the function execution.
|
2011-10-22 06:33:24 +00:00
|
|
|
* @returns {*} DeferId that can be used to cancel the task via `$defer.cancel()`.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.$defer#cancel
|
|
|
|
|
* @methodOf ng.$defer
|
2011-10-22 06:33:24 +00:00
|
|
|
*
|
|
|
|
|
* @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.
|
2011-02-15 06:12:45 +00:00
|
|
|
*/
|
2011-11-02 23:32:46 +00:00
|
|
|
function $DeferProvider(){
|
2012-05-23 06:05:26 +00:00
|
|
|
this.$get = ['$rootScope', '$browser', '$log', function($rootScope, $browser, $log) {
|
|
|
|
|
$log.warn('$defer service has been deprecated, migrate to $timeout');
|
|
|
|
|
|
2011-11-02 23:32:46 +00:00
|
|
|
function defer(fn, delay) {
|
|
|
|
|
return $browser.defer(function() {
|
|
|
|
|
$rootScope.$apply(fn);
|
|
|
|
|
}, delay);
|
|
|
|
|
}
|
2011-10-22 06:33:24 +00:00
|
|
|
|
2011-11-02 23:32:46 +00:00
|
|
|
defer.cancel = function(deferId) {
|
|
|
|
|
return $browser.defer.cancel(deferId);
|
|
|
|
|
};
|
2011-10-22 06:33:24 +00:00
|
|
|
|
2011-11-02 23:32:46 +00:00
|
|
|
return defer;
|
|
|
|
|
}];
|
|
|
|
|
}
|