Helper Not Running

I have a helper that isn’t running when a session variable changes. When the user submits a form, the event handler can run for up to 30 seconds, so I update a session variable with the status. These session variable updates don’t cause the helper to run. However, if I introduce a syntax error in the event so that it aborts, the helper runs with the latest session variable value.

Template.Games.events({
    'submit': function(e, t){
        Session.set('infoMessage', 'Started processing..');
         .....
    }
});
Template.Games.helpers({
    "infoMessage": function() {
	console.log('infoMessage helper: ' + Session.get("infoMessage"));
	return Session.get("infoMessage");
    }
});

Have you considered using a ReactiveVar?

Template.Games.onCreated({
  this.infoMessage= new ReactiveVar(); // Or just insert a string that should be displayed at the begining
});

Template.Games.helpers({
  infoMessage: function () {
    return Template.instance().infoMessage.get();
  }
});

Template.Games.events({
  'submit': function(evt, template) {
     template.infoMessage.set("Started processing...");
     ...
  }
});

If that doesn’t work, could you poste more of your event code?

I’m thinking that your CPU is running flat out and cannot react to anything else. You could have an infinite loop in your code (an easy way to introduce one is to get and set the same reactive variable* in an autorun or helper).

As @jhuenges says - maybe you should show us some more code

* Most likely when you have a complex variable (array or object) and no equals function to prevent invalidation.

Thanks for the responses. I think @robfallows is correct that this is related to high CPU. I am now using reactiveVar with the same result.

I was doing some gets & sets in the event code but have removed the gets which were there for debug.

The event code that runs on the form submit, calls a function that runs in a client/server shared folder. This function runs a long series of calculations and potentially dozens of db inserts and updates

They’re not a problem in events (unless you’ve also put them in an autorun), so if you need to debug that’s fine.

That sounds a little bit dubious :wink: - are you needing client computation for optimistic UI? It may be better to move this stuff into a method, especially as the client/server database “reconciliation” will be adding to the load.

Oh, Methods! That makes a huge difference. How many reasons to love Meteor, let me count the ways.

Thanks @robfallows

1 Like