Meteor.wrapAsync doesn't return value


#1

Hello,

I cannot get the wrapAsync method working, following a very simple code that doesn’t work, anybody can tell what is wrong ?

Meteor.methods({
testMethod: function (var1) {
var syncFunc = Meteor.wrapAsync(testAsync);
var result = syncFunc(var1);

  console.log(result);

}
});

function testAsync(myVar){
return 'Var is: ’ + myVar;
}

Thanks,


#2

An async function must have a callback with a signature of (error, result) for this to work. So if your “async” function looked like this it should work:

function testAsync(myVar, callback) {
  callback(null, 'Var is: ' + myVar);
}

In which null means “no error”.


#3

Awesome, thank you very much !!!