Is reactive var async?


I’m using several reativevar’s in my application. Recently I had a user with a strange database-entry. The only explanation so far I have been able to come up with, is that a specific reactivevar did not, immediately, return the value I just had writen to it. So, my question is: is a reactive var asynchronus? Could it “take a while” for a value to be processed?

(Of course, I would create a second variable, not reactive to remedie this, but I want to be sure first. I cannot really read the whole code for reactivevar, and I am not after reading the documenation…)



ReactiveVar is not asynchronous.

However, you may be using asynchronously.

For example, this is synchronous:

this.someReactiveVar = new ReactiveVar();
console.log(this.someReactiveVar.get()); // "99"

This is asynchronous:

this.someReactiveVar = new ReactiveVar();'someMethod', (error, result) => {
  if (!error) this.someReactiveVar.set(result);
console.log(this.someReactiveVar.get()); // "undefined"

In the latter example the correct way to reference the ReactiveVar outside the is within a reactive context, like a Tracker.autorun for example.

Hi Rob,

thank you for your clear answer! Alas, this means there is an error in my code :sunglasses:

(This is a really strange error, that occured now, once, on I think 10.000 cases… so classic debugging it is!)