I am running into something I don\'t understand with Meteor. I have this method, which takes a query, sends it to amazon, and then in the callback of that function I try to
Meteor methods are asynchronous, you can get the result by many way.
Using npm module fibers (The other answer are explaining it very clearly).
There are some other way w/o using npm module :
Via Session variable :
Meteor.call('myMethod',args, function(error, result) {
if (error) { Session.set('result', error) } // Note that the error is returned synchronously
else {
Session.set('result', result) // Using : Session.get('result') will return you the result of the meteor call !
}
});
Or Via template variable :
Template.hello.onCreated(function helloOnCreated() {
// counter starts at 0
this.message = new ReactiveVar(0);
});
Template.hello.helpers({
message() {
return Template.instance().message.get();
},
});
Template.hello.events({
'click button'(event, instance) {
Meteor.call('myMethod', args, function (error, result) {
if (error) { Template.instance().message.set(error); }
else {
Template.instance().message.set(result);
}
})
},
});
Hope it will help !