Meteor.wrapAsync doesn't return value

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,

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”.

1 Like

Awesome, thank you very much !!!

1 Like