Skip to content

Meteor.subscribe onReady callback called before sub marked ready #4614

Closed
@alexcorre

Description

@alexcorre

Hi Meteor Team!

I had a question about these lines of code: https://github.com/meteor/meteor/blob/master/packages/ddp/livedata_connection.js#L1377-L1379

When we receive a ready message for a subscription we call the readyCallback before actually marking the subscription as ready. Is there a reason for this? I want to achieve the following but cannot:

Lets say we have a subscription called someSub that publishes some interesting data. This interesting data is used by getSomeData(). I want to make sure that developers on my team dont call getSomeData until the someSub subscription is ready, since it could lead to unpredictable and particularly buggy state.

Now, in the example below, I call getSomeData within the onReady callback function, and it still throws an error.

MySubs.something = Meteor.subscribe('someSub', function() {
    // do some stuff...

   var data = getSomeData();

   // do some more stuff...
});

inside getSomeData

function getSomeData() {
   if (!MySubs.something.ready()) {
     // THIS THROWS when i call getSomeData from the ready callback.
    throw new Error()
  }

  // do some important stuff with the data published by someSub
}

This may just be an edge case, but to me. it seems that ready() should return true from inside the readyCallback. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions