Event listener problem on client; observing collection


I am trying to make a button component. When clicked, it will disable and say what it’s currently doing (read from a server collection).

On my client I have something similar to as follows

Template['MachineButton'].onCreated(function () {
  this.lastMessage = new ReactiveVar('OK');
  this.executing = new ReactiveVar(false);
  FlowRouter.subsReady('machine', () => {
    Machine.connections.find({ name: 'messages' }).observe({
      changed: (doc) => {

My server does something like as follows:

// factory method to create TCP sockets
Machine._messages = Machine._createConnection('names');
Machine._messages.addListener('data', function (data) {
  Machine.connections.update({ name: 'messages' }, {
    $push: {
      $each: [{
        timestamp: new Date,
        message: data.toString('ascii')
      $sort: { timestamp: 1 },
      $slice: -20

It seems like this executes too slowly. It never changes the messages on the page, even though it seems like it should. Why does this happen? Is it long-polling? How can you tell?


What does your template helper look like?

Have you looked at DDP traffic in the web inspector to check that changes are being sent?

Have you added a console.log in the changed block to check that changes are being picked up?


I found out the problem seems to be using the following:

Meteor.apply('loadJobs', Cycles.findOne().jobs, {
  wait: false
}, function (err, result) {

Changing wait to true worked, but I can’t seem to get it to run multiple promises in sequence