0

Heres my code. I basicly want to return the 'body' var in my getFollows function. Setting vars obviously dont work, no idea how to get the variable. I can't change getUserFollowedChannels because its a package, and I need to return it to the function directly because of meteor server->client stuff.

'twitch.getFollows'() {
    var followers = twitch.getUserFollowedChannels('atlatonin', function(err, body) {
        if (err) {
            return err;
        } else {
            console.log(body.follows[0].channel.display_name);
            return body.follows[0].channel.display_name;
        }
    });
    return followers;
},
nn3112337
  • 459
  • 6
  • 21
  • Perhaps a dup of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call). – jfriend00 Jul 05 '16 at 03:28
  • Just an alias, basicly reads as 'twitch.getFollows': function() {} – nn3112337 Jul 05 '16 at 03:28

1 Answers1

1

You can pass a callback function as below:

'twitch.getFollows': function(done) {
     twitch.getUserFollowedChannels('atlatonin', done);
 }

And invoke the function as below:

twitch.getFollows(function(err, body) {
    if (err) {
        console.log(err);
        //return err;
    } else {
        console.log(body.follows[0].channel.display_name);
        //return body.follows[0].channel.display_name;
    }
});
Dhananjaya Kuppu
  • 1,322
  • 9
  • 10