Last active
August 29, 2015 14:22
-
-
Save tomsmeding/3c9bb63cffe3465a6177 to your computer and use it in GitHub Desktop.
Async function to sync using node fibers/future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrapAsync(fn) { | |
return function () { | |
var fut=new Future(); | |
var args=Array.apply(Array,arguments); | |
args.push(fut.resolver()); | |
fn.apply(this,args); | |
return fut.wait(); | |
} | |
} |
Shouldn't it be
function wrapAsync (fn) {
return function () {
var args = new Array(arguments.length + 1);
var fut = new Future();
for (var i = 0; i < arguments.length; i++) args[i] = arguments[i];
args[i] = fut.resolver();
fn.apply(this, args);
return fut.wait();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As stolen from https://github.com/meteor/meteor/blob/832e6fe44f3635cae060415d6150c0105f2bf0f6/packages/meteor/helpers.js#L90 ;)