using `Future.wrap`
Oh, by the way, fyi I ran into an issue with Future.wrap the other day. The source looks like this:
Future.wrap = function(fn, idx) {
idx = idx === undefined ? fn.length - 1 : idx;
fn.length is the
declared number of function arguments (
MDC), not the actual length of the arguments. I had some other function wrapper I had to use between the async API method and Future.wrap, and
it was returning a vararg style function:
function anotherWrapper (fn) {
...
return function (/* arguments */) { return fn.apply(...) };
}
so inside of Future.wrap, fn.length was coming out 0.
So an edge case to watch out for when implementing Meteor.wrapAsync is when you're looking for the callback at the end of the argument list, make sure you're using arguments.length instead fn.length :)
Andrew