wrapAsync issues


#1

Hi there,
I need to call an async method in a meteor method. I’m trying to use Meteor.wrapAsync for this, but it is only returning {state: 'pending'}. How can I resolve this?

The normal async request:

            chargebee.portal_session.create({
                embed: true,
                redirect_url : "https://example.com",
                customer : {
                    id : Meteor.userId()
                }
            }).request((error, result) => {
                 console.log(result);
            });

The request with wrapAsync returning state pending:

        try {
            var query = chargebee.portal_session.create({
                embed: true,
                redirect_url : "https://example.com",
                customer : {
                    id : Meteor.userId()
                }
            });
            var result = Meteor.wrapAsync(query.request)();
            console.log("result", result);
            return result;
        } catch (error) {
            throw new Meteor.Error(500, 'Failed to retrieve billing page', error);
        }

#2

It looks like you are applying wrapAsync to the wrong thing? I suspect what you are looking for is something like:

var syncChargebeeCreate = Meteor.wrapAsync(chargebee.portal_session.create, chargebee.portal_session);
var result = syncChargebeeCreate({ ... your options });
console.log(JSON.stringify(result,null,4));

#3

I tried this, too. It doesn’t work, because request isn’t called sync or like in your case not at all.


#4

Okay, this is probably beyond my capabilities. Is it possible to call the API directly with HTTP.get()? (in synchronous mode)


#5

Try this : meteorhacks:async

var res = Async.runSync(function(done){
    chargebee.portal_session.create({
         embed: true,
         redirect_url : "https://example.com",
         customer : {
               id : Meteor.userId()
          }
   }).request((error, result) => {
           done(error, result);
   });
});
console.log(res);

#6

Thank you. This works, but doesn’t it freeze the entire server until it completes? This would not work in my case.