Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the "null" publish ready?

Tags:

meteor

publish

Having the following code on the server:

Meteor.publish(null, function(){
    // Return some cursors.
})

will according to the documentation have the following effect: the record set is automatically sent to all connected clients.

How can I on the client side determine if all the documents published by this function has been received? If I would use a subscription instead, it would provide me with a ready callback, letting me know when all the documents been received. What's the matching way here? Or are the documents already received at the client when my client side code starts to execute?

like image 279
Peppe L-G Avatar asked Nov 10 '13 14:11

Peppe L-G


1 Answers

I'm afraid there's no way to have a ready callback for so called universal subscriptions you mentioned above. Just have a look at this part of Meteor's code, where the publish and subscription logic is defined on the server. For convenience I'm copy/pasting the code below:

ready: function () {
  var self = this;
  if (self._isDeactivated())
    return;
  if (!self._subscriptionId)
    return;  // unnecessary but ignored for universal sub
  if (!self._ready) {
    self._session.sendReady([self._subscriptionId]);
    self._ready = true;
  }
}

The _subscriptionId is only given to named subscriptions, which are those that you would manually define using Meteor.subscribe method. The subscriptions corresponding to null publish functions, doesn't have their own _subscriptionId, so as you can see from the code above, the server is not event trying to send the ready message to the client.

like image 90
Tomasz Lenarcik Avatar answered Nov 20 '22 04:11

Tomasz Lenarcik