This Meteor server code makes a DDP call to external service serv2
and once it gets the result, it suppose to send back to the client which made the call, but it is not.
What is the best fix? Should I take advantage of MongoDB reactiveness?
/////////////////////////// client/main.js \\\\\\\\\\\\\\\\\\\\\\\\\\
Template.hello.events({
'click button'(event, instance) {
Meteor.call('service2', function (err, res) {
if (!err) {
console.log('got it'); //=> prints right away without waiting.
console.log(res); //=> print undefined <==================
instance.msg.set(res);
}
});
}
});
/////////////////////////// server/app.js \\\\\\\\\\\\\\\\\\\\\\\\\\
import { Meteor } from 'meteor/meteor';
import { DDP } from 'meteor/ddp-client';
let serv2 = DDP.connect('localhost:7001');
Meteor.methods({
'service2': function () {
serv2.call('service2', function (err, res) {
if (!err) {
console.log(res); //=> prints OK
return 'service 1 calling service 2 <br> + res'; //<====== failed to return.
}
});
}
});