So, I have seen the Meteor.wrapAsync
applied to Stripe examples several different places. I need to do the same thing, but with Recurly.
Meteor.methods({
getAccount: function(accountInfo) {
check(accountInfo, {...});
try {
// http://stackoverflow.com/questions/26226583/meteor-proper-use-of-meteor-wrapasync-on-server
// get a sync version of our API async func
let getAccountSync = Meteor.wrapAsync(recurly.accounts.get);
// call the sync version of our API func with the parameters from the method call
let result = getAccountSync(accountInfo.account_code);
}
catch(error) {
console.log(error);
}
}
});
I have also tried adding a context to it like…
Meteor.wrapAsync(recurly.accounts.get, recurly.accounts);
Admittedly I still find all of this pretty confusing so a well laid out article / code example reference would be awesome to have if anyone knows of one. Thanks.
I am using this NPM package https://github.com/robrighter/node-recurly.
When you say “wrapAsync not returning anything”, do you mean getAccountSync
is undefined in your example when run? If so maybe add a console.log(recurly);
just before your wrapAsync
call to make sure you have access to the recurly
object. It not you’ll likely have to import
or require
it (assuming Meteor 1.3).
Where are you checking for the result
to your call? If it’s outside your try/catch
block it will be undefined, because let
creates block scoped variables. You could try:
Meteor.methods({
getAccount: function(accountInfo) {
check(accountInfo, {...});
let result;
const getAccountSync = Meteor.wrapAsync(recurly.accounts.get, recurly.accounts);
try {
result = getAccountSync(accountInfo.account_code);
}
catch(error) {
console.log(error);
}
// result should be available here.
}
});
I think I found the problem, but not the solution. Basically I have moved to using Futures for this and it seems to be working great. I am not sure exactly how to problem solve it specifically, but I believe the problem is related to what @hwillson’s suggestion. I don’t think the recurly.accounts.get
was returning anything. And I don’t think recurly.accounts
is the correct context for wrapAsync
.