diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-06-28 00:10:40 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-06-28 00:10:40 -0700 |
commit | e7948013f3c3741606159e0c86f03dbb9e20ff2b (patch) | |
tree | ee989acf11cf92174800d2710f6dbb392438303b /lib/async.js | |
parent | a95455ce36253efd3160682d8e839e783eedc0fd (diff) | |
download | async-e7948013f3c3741606159e0c86f03dbb9e20ff2b.tar.gz |
added async.asyncify. closes #671
Diffstat (limited to 'lib/async.js')
-rw-r--r-- | lib/async.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/async.js b/lib/async.js index 0da1062..6191b57 100644 --- a/lib/async.js +++ b/lib/async.js @@ -1221,6 +1221,21 @@ }; }; + async.wrapSync = + async.asyncify = function asyncify(func) { + return function (/*args..., callback*/) { + var args = _baseSlice(arguments); + var callback = args.pop(); + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); + } + callback(null, result); + }; + }; + // Node.js if (typeof module !== 'undefined' && module.exports) { module.exports = async; |