Is it possible to make a Meteor.call synchronous and how?
var Tget = Meteor.wrapAsync(T.get);
Meteor.methods({
'screenName': function() {
return Tget({
q : '#UCLA',
count : 1
}).status[0].user.screen_name;
}
});
This will make the function on the server side synchronous, right?
But I need Meteor.call itself to be synchronous. I need to get the result from Meteor.call before the process continues to render other stuff… is it possible?
You can use a callback on the client, or (better) you can use async
and await
on the client with a little effort:
1 Like
Note that these are all just syntax stuff - at the end of the day, no, there’s nothing you can do to make an asynchronous call from the client block everything else. You need to explicitly handle the case before and after data has been returned.
4 Likes
My solution:
const Future = require('fibers/future');
const createCustomer = function(userId) {
const future = new Future();
Meteor.call('stripeCreateCustomer', userId, function(err, customer) {
if(err) return orbiter.core.throwError(err);
future.return(customer);
});
return future.wait();
};
let customer = user.stripe?.customer;
if(!customer) customer = createCustomer(user._id); // magic synchronous call !