I am trying to make this function synchronous. I read a few stack overflow messages about Async, but I can't figure out how I can do this synchronously. It is asynchronous at the moment, so it returns undefined before going into the callback function.
I call it on the client side:
Meteor.call('screenName',function(error,result) { if (error) { console.log(error); } else { window.alert(result); } }
And this is the server side method:
Meteor.methods({ 'screenName': function() { T.get('search/tweets', { q:'#UCLA', count:1 }, function(err,data,response) { var temp = data.statuses[0].user.screen_name; console.log(temp); return temp; } ) } });
I am using the Twitter API, and what I want to do is basically extract the screen name from JSON and return it a client-side variable. But this returns undefined because the callback compiles after the compiler reaches the end of the screenName function.
I want it to return a value from a callback function, but reading other examples did not help me understand how I can convert my code. I need to make this function synchronous, but I don't know how to do it.
source share