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


#1

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


#2

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.


#3

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


#4

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


#5

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.


#6

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"});
        });
    }
});

#7

Now, I use iron-router.


#8

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');
  });
});

#9

I will try… :wink:


#10

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


#11

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


#12

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.