summaryrefslogtreecommitdiff
path: root/lib/async.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/async.js')
-rw-r--r--lib/async.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/async.js b/lib/async.js
index 4257f0d..86c810a 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -1282,4 +1282,26 @@
root.async = async;
}
+ function ensureAsync(fn) {
+ return function (/*...args, callback*/) {
+ var args = _baseSlice(arguments);
+ var callback = args.pop();
+ args.push(function () {
+ var innerArgs = arguments;
+ if (sync) {
+ async.setImmediate(function () {
+ callback.apply(null, innerArgs);
+ });
+ } else {
+ callback.apply(null, innerArgs);
+ }
+ });
+ var sync = true;
+ fn.apply(this, args);
+ sync = false;
+ };
+ }
+
+ async.ensureAsync = ensureAsync;
+
}());