aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/defer.js
diff options
context:
space:
mode:
authorMisko Hevery2012-03-23 14:03:24 -0700
committerMisko Hevery2012-03-28 11:16:35 -0700
commit2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (patch)
treee7529b741d70199f36d52090b430510bad07f233 /src/ng/defer.js
parent944098a4e0f753f06b40c73ca3e79991cec6c2e2 (diff)
downloadangular.js-2430f52bb97fa9d682e5f028c977c5bf94c5ec38.tar.bz2
chore(module): move files around in preparation for more modules
Diffstat (limited to 'src/ng/defer.js')
-rw-r--r--src/ng/defer.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ng/defer.js b/src/ng/defer.js
new file mode 100644
index 00000000..f2a893bc
--- /dev/null
+++ b/src/ng/defer.js
@@ -0,0 +1,45 @@
+'use strict';
+
+/**
+ * @ngdoc function
+ * @name angular.module.ng.$defer
+ * @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', function($rootScope, $browser) {
+ function defer(fn, delay) {
+ return $browser.defer(function() {
+ $rootScope.$apply(fn);
+ }, delay);
+ }
+
+ defer.cancel = function(deferId) {
+ return $browser.defer.cancel(deferId);
+ };
+
+ return defer;
+ }];
+}