Meteor subscribe callback

meteor

According to this article here:

https://dweldon.silvrback.com/common-mistakes

Subscriptions don't block

Many aspects of the framework seem like magic. So much so that it may
cause you to forget how web browsers work. Take this simple example:

Meteor.subscribe('posts');

var post = Posts.findOne();

The idea that post will be undefined is the root cause of roughly one
in twenty meteor questions on stackoverflow.

So then why doesn't subscribe have a callback, and if it does, why isn't it referenced more often by the Meteor literati?

Why don't we have:

Meteor.subscribe('posts', function(err, posts){

//when the items/posts actually arrive

}); 

I hope my question makes sense.

Best Solution

Maybe I don't get the question, but the Meteor.Subscribe function has callbacks named onError and onReady methods.

Optional. May include onError and onReady callbacks. If a function is passed instead of an object, it is interpreted as an onReady callback.

From docs.

For example.

Meteor.subscribe("posts", {
  onReady: function () { console.log("onReady And the Items actually Arrive", arguments); },
  onError: function () { console.log("onError", arguments); }
});

Also check this GitHub issue

Related Question