Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

closure is triggered before subscription is ready #89

Open
jaddoescad opened this issue Jan 9, 2017 · 3 comments
Open

closure is triggered before subscription is ready #89

jaddoescad opened this issue Jan 9, 2017 · 3 comments

Comments

@jaddoescad
Copy link

            let users = MeteorCollection<User>(name: "users")
      Meteor.subscribe("users") , callback: {
                        var id = Meteor.client.userId()
                        self.navigationController!.performSegue(withIdentifier: "LoginSuccess", sender: nil)
                        let json = JSON(users.findOne(id!)?.services)
                        print(json["facebook"]["id"])
                    })

The following code above is supposed to retrieve the user's information when I subscribe to "users". The problem is sometimes I get null for user information. I'm really not sure why?

this is my server code:

  Meteor.publish("users", function () {
if (this.userId) {
    return Meteor.users.find({_id: this.userId}               
    {fields: {'services.resume': 0}});
  } else {
    this.ready();
  }
});

How can I make sure that the closure is only triggered once I am ready to receive everything.

@mastertrunk
Copy link

very annoying issue, when I subscribe to my messages, sometimes i get info, sometimes i dont. my guess is somehow it thinks that there is nothing to load, i'm not sure why. you should try and look at meteor-ios,never happened to me there.

@mastertrunk
Copy link

a workaround is to also use abstract collection notifications, it may give them to you one by one, but it mostly never fails

@siegesmund
Copy link
Owner

siegesmund commented Jan 12, 2017

I can't tell what you're doing from the code you've provided. But I see a number of potential problems. First, you shouldn't put your navigation logic inside subscription callback. That's opening up a number of potential problems and is going to make this harder to reason about. Second, you shouldn't define your collections inside your view controllers. When you navigate away users is going to disappear.

What do your DDP logs look like on the client. They'll show you exactly what is being transmitted from the server.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants