Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "syncho", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Fast and lean abstraction for node Fibers. Easily run asynchronous functions synchronously.", | ||
@@ -5,0 +5,0 @@ "author": "Jerome Touffe-Blin <jtblin@gmail.com> (http://about.me/jtblin)", |
@@ -67,11 +67,15 @@ (function () { | ||
return function (/* arguments */) { | ||
var cb = arguments[arguments.length-1]; | ||
delete arguments[--arguments.length]; | ||
var args = arguments, cb = args[args.length-1]; | ||
if (typeof cb !== 'function') throw new Error('Must pass a callback function to async functions'); | ||
try { | ||
cb(null, fn.apply(cxt, arguments)); | ||
} | ||
catch (err) { | ||
cb(err); | ||
} | ||
delete args[--args.length]; | ||
process.nextTick(function () { | ||
Sync(function () { | ||
try { | ||
cb(null, fn.apply(cxt, args)); | ||
} | ||
catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -78,0 +82,0 @@ }; |
16229
188