How to wait on for calling "Meteor.methods()"?

I create the Meteor.methods() to generate my report, but I want to wait on for ready like pub/sub.
How to do this?

First of all, you don’t make any sense.

Either you use Iron Router, then you can use the waitOn() function, either you use FlowRouter, then you can test for FlowRouter.subsReady(), either you use template subscriptions and then you would test Template.subscriptionsReady.

Anyway this topic is more than covered in docs and tutorials. You should get started by reading those or even the discover meteor book. But I think if you continue to post vague questions, without being polite at all like you are being now, people will just ignore you in the future.

maybe you mean that you want to make an async call?

the method returns immediately, but you want to wait for the result? That’s an async call

I think that, we can’t wait for Meteor.methods() on router.

Perhaps something like can work. Assuming user clicks on a button.

  1. Show a Loading message or animation (perhaps a full screen overlay) and call the method.
  2. When the method returns, send the user to result page.

We can’t do this if user comes to the result page directly by url. In that case.

  1. Send the user to a page which shows a loading animation and calls the method.
  2. When the method returns, send the user back to result page.

OR

1.Show the loading message on result page itself and hide it when method returns.

btw, I think you can wait on method calls. I’ve never tried this so I can’t say if it’ll work fine.

FlowRouter.route('/blog/:postId', {
    action: function(params) {
        Meteor.call('foo', function (err, res) {
            FlowLayout.render("mainLayout", {area: "blog"});
        });
    }
});

Now, I use iron-router.

It’s not that different. (again, I didn’t test this code, I was just looking at some docs)

Router.route('/', function () {
  var self = this;
  Meteor.call('foo', function (err, res) {
    self.render('MyTemplate');
  });
});

I will try… :wink:

@elgusto, be kind. Not everybody’s English is good enough to understand docs and being polite.

2 Likes

EDIT: The approach @mnmtanish proposes worked for our project.

I’ve run into a similar issue as you. I need my Meteor.call to be waited on.
Kindly let me know if the suggested solution by “Mnmtanish” worked out for you.