Search code examples
asynchronousmeteormethodssynchronizationcall

Why asynchronous Meteor.call() doesn't return anything


I have the following code on the client-side:

Meteor.call("getOldTests", m_user, test_id, course, language, function (error, result) {
            console.log("result: " + result);
            if (error) {
                Notifications.error(error.reason, 'We are working on this problem');
            } else {
                console.log(result);
                data.set(course, result);
            }

        });

where the server-side has the following method:

Meteor.methods({
    getOldTests: function (m_user, test_id, course, language) {
        var tests = Tests.findOne({email: m_user.email, course_en: course, test_id: test_id});
        if (tests) {
            console.log(tests);
            return Questions.find({course_en: course, variant: tests.variant, language: language});
        } else {
            return false;
        }
    },});

Where the variable data is reactive-dict

So, why is nothing executed inside of my Meteor.call() function on the client-side (no console output) while indeed it calls the method on the server-side (console outputs intermediate results)?

Thanks,


Solution

  • It looks like you are using a method where a pub-sub is more appropriate:

    server:

    Meteor.publish('getOldTests',function (m_user, test_id, course, language) {
      var tests = Tests.findOne({email: m_user.email, course_en: course, test_id: test_id});
      if (tests) return Questions.find({course_en: course, variant: tests.variant, language: language});
      else this.ready();
    });
    

    client:

    Meteor.subscribe('getOldTests',m_user, test_id, course, language);