Meteor.call("myMethod", function (error, result) { // Async call
if (error) {
// Error handling code
} else {
Session.set("results", result); // Set the result information as a session to retrieve outside of the call
}
});
Because I can’t seem to get the result value to outside the call without the session. This is what pretty much every example I’ve seen uses.
However I don’t want to use Session to get the call result value.
My initial theory was that it’s the scope but I declared a variable outside the call and the assigned the result to it and it returns undefined.
Can someone explain (and I do want the explanation of why) if it is really necessary to use Session and if not how to get the result value to outside the call without getting undefined values.
On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn’t have fibers, so there is not actually any way it can block on the remote execution of a method.
Remember, the method call is asynchronous - if you add console.log("Inside method: ", testVariable) inside the else you’ll see that the console.log outside the method call will return first.
This is why Session is commonly used, since it’s the easiest way to get the return value when it becomes available - making use of Meteor reactivity.
Ok @TwinTails, but can you please give me an example of a simple stub to use in this case to solve this issue? I don’t really know how a stub looks like in code, as I only know the description of what a stub is.