Send reactive signal from server to client?

I am constructing a chart where I aggregate data on the server and send it to the client via a Meteor method. Since Meteor methods are not reactive, I need to trigger the template to run the method requesting the data reactively.

How can I send a signal from the server to the client when relevant server data has changed, so the chart can be re-rendered (via autorun)?

The closest approach I have thought of is to use percolatestudio:publish-counts to send a count of the documents, which will trigger the template autorun function. This seems slightly ‘hacky’, since all I really need is a reactive signal for the autorun function to be triggered.

Why not use Meteor’s standard pub/sub mechanism?

However, you could add a server-side observer on to the collection and use that with the low-level pub/sub API to send a “ready” message to the client.

The jcbernack:reactive-aggregate package basically uses this technique, although it’s probably a little past its use-by date, as it relies on the meteorhacks:aggregate package which has exhibited a few issues lately. It may give you some pointers, though.

Yes, standard pub/sub sounds doable. I assume the server that generates the data for the chart reacts on something? If it is the change of a collection then just do a client sub on that collection, observe it and let that trigger your call. Alternatively, you could create a “events” collection that the server updates after it has done it’s job. Client subscribes on the events and does stuff.