0

Here is my code,

googleContacts:function()
        {

            var opts= { email: Meteor.user().services.google.email,
              consumerKey: "xxxxxxxx",
              consumerSecret: "xxxxxxxxxx",
              token: Meteor.user().services.google.accessToken,
              refreshToken: Meteor.user().services.google.refreshToken};

            gcontacts = new GoogleContacts(opts);

            gcontacts.refreshAccessToken(opts.refreshToken, function (err, accessToken)
             {
                if(err)
                {
                    console.log ('gcontact.refreshToken, ', err);
                    return false;
                }
                else
                {
                    console.log ('gcontact.access token success!');
                    gcontacts.token = accessToken;
                    gcontacts.getContacts(function(err, contact) 
                    {
                      console.log(contact);
                       return contact;//want to return this value
                    })

                }
             });

        }

I want to return the contact to the called method,as it is in a inner function i'm getting a bit difficult to return it to the called method.If it is in client side,then we can store the value in a session variable and we can return that,but this is a server side method,How to do this?

2
  • 1
    See the "how to use async..." section here. Commented Mar 31, 2014 at 12:07
  • Yeah tried that,but i didn't get it correct,can anyone show me how to do it? Commented Mar 31, 2014 at 12:44

1 Answer 1

1

Use Futures:

Future = Npm.require('fibers/future');

Meteor.methods({

  methodname: function() {
    var fut = new Future();
    apiCall(function(err, res) {
      fut.return(...);
    });
    return fut.wait();
  },

});
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome,Awesome,Awesome and let me ask a question,is this the proper way of doing things?,but the result is awesome,doing this whole day and didn't find a way to do it.
Yes, this is the Meteor way :-)
What about _wrapAsycn()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.