[SOLVED] I have no idea how Meteor.wrapAsync works


Hello everyone,

I’ve written a username generator for my application this morning. Here is it’s source code. As you can see, I just call cat/grep on my OSs dictionaries.

It works. Perfectly. But I have no idea why. The question come when you see pickAdjective and pickNoun functions. They make an exec call and then… What? They don’t return anything and if you see the next lines, I never define any callbacks. There is not a single line of code that says “hey, just return stdout” or whatever. But the code works and returns the proper values at all times.

I’m not complaining of course, it just blows my mind and I feel uncomfortable not understanding the process


Never used wrapAsync, but it seems useless here. Maybe you can try to remove it and see what happens:

var pickAdjective = function(callback){
  exec("cat /usr/share/dict/words | grep ...", callback);
var pickNoun = function(callback){
  exec("cat /usr/share/dict/words | grep ...", callback);


This will not work, because exec runs asyncronously and I need my method to return their result.

It’s as if in client-side JS you’d do something like

$.ajax('/REST/nouns/pick/1', callback);
$.ajax('/REST/adjectives/pick/1', callback);


Didnt look at ur code but this video explains it a bit. IIRC .wrapAsync has changed a bit in the last few releases so check the docs.



Indeed that helped a lot. What wrapAsync does seems to do is that it just returns the second parameter of the passed function by convention.

Of course that means that if the callback has a signature different than one of (err, result) wrapAsync will probably return unpredictable results.