I just don’t agree with @serkandurusoy who “I strongly suggest against using this pattern”.
This is actually how meteor does latency compensation…
Eg:
// Define the method on both client and server
Meteor.methods({
test: function() {
if (this.isSimulation) {
return 1; // Client wants this to be 1
} else {
return 2; // Server wants this to be 2
}
}
});
Template.hello.events({
'click button': function () {
// Call the test method sync
var clientResult = Meteor.apply('test', [], {returnStubValue: true},
function(err, serverResult) {
if (clientResult !== serverResult) { // 1 !== 2
// If client and server disagree let server correct the client
Session.set('result', serverResult); // -> 2
}
}
);
// Expect that the stub is correct
Session.set('result', clientResult); // -> 1
}
});