Make Meteor method synchronous
Simply use Meteor.wrapAsync
to turn your asynchronous T.get
into a synchronously styled one!
It won't actually get executed in a pure "synchronous" way though, it is using a trick known as a Fiber, but you should read the docs to learn more.
Here goes:
var Tget = Meteor.wrapAsync(T.get);
Meteor.methods({
'screenName': function() {
return Tget({
q : '#UCLA',
count : 1
}).status[0].user.screen_name;
}
});
Browser-to-server, it is not possible to call methods synchronously. You're stuck with callback-style code. Synchronous calls are only possible on the server.
http://docs.meteor.com/#/basic/Meteor-call
On the client
Methods called on the client run asynchronously, so you need to pass a callback in order to observe the result of the call. The callback will be called with two arguments, error and result. The error argument will be null unless an exception was thrown. When an exception is thrown, the error argument is a Meteor.Error instance and the result argument is undefined.
On the server
On the server, you don't have to pass a callback — the method call will simply block until the method is complete, returning a result or throwing an exception, just as if you called the function directly.
However, synchronous style code for the server depends if everything else is synchronous. You might want to read the APIs docs if it is possible to write the Twitter API call synchronously. Otherwise, you'll be writing asynchronous code in the end.