Meteor.call(name, [arg1, arg2...], [asyncCallback])
(1) name String
(2) Name of method to invoke
(3) arg1, arg2... EJSON-able Object [Optional]
(4) asyncCallback Function [Optional]
On one hand, you can do : (via Session variable, or via ReactiveVar)
var syncCall = Meteor.call("mymethod") // Sync call
It mean if you do something like this, server side you will do :
Meteor.methods({
mymethod: function() {
let asyncToSync = Meteor.wrapAsync(asynchronousCall);
// do something with the result;
return asyncToSync;
}
});
On the other hand, sometimes you will want to keep it via the result of the callback ?
Client side :
Meteor.call("mymethod", argumentObjectorString, function (error, result) {
if (error) Session.set("result", error);
else Session.set("result",result);
}
Session.get("result") -> will contain the result or the error;
//Session variable come with a tracker that trigger whenever a new value is set to the session variable. \ same behavior using ReactiveVar
Server side
Meteor.methods({
mymethod: function(ObjectorString) {
if (true) {
return true;
} else {
throw new Meteor.Error("TitleOfError", "ReasonAndMessageOfError"); // This will and up in the error parameter of the Meteor.call
}
}
});
The purpose here is to show that Meteor propose various way to communicate between the Client and the Server.