Skip to content

Instantly share code, notes, and snippets.

@tomsmeding
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomsmeding/3c9bb63cffe3465a6177 to your computer and use it in GitHub Desktop.
Save tomsmeding/3c9bb63cffe3465a6177 to your computer and use it in GitHub Desktop.
Async function to sync using node fibers/future
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();
}
}
@lieuwex
Copy link

lieuwex commented Jun 22, 2015

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