0

I'm following a guide over at The Meteor Chef to wrap an asynchronous function and call it synchronously. However, when the code executes it appears to just jump over the method call entirely. Not sure what I'm doing incorrectly.

if (!err) {
  Meteor.methods({
    'ldapLogin': function(username, password) {
      var syncFunc = Meteor.wrapAsync(processLdapLogin);
      var result = syncFunc(username, password, Meteor.user());

      console.log(result);
    }
  });
  Meteor.call('ldapLogin', username, password);
}
illya
  • 377
  • 5
  • 17
  • Where are you calling `processLdapLoginWrapAsync()` from? All you did was declare a Meteor method, you have to call it in order for it to work. – Brendan Turner Jan 04 '16 at 20:26
  • Hmm, this is what I was wondering, but none of the multiple guides I've read online actually show calling the newly created method... – illya Jan 04 '16 at 20:34
  • Doesn't seem to be a need to put it in a Meteor method at all. Remove lines 2,3,8,9 and see how that goes. [more info](http://stackoverflow.com/questions/26226583/meteor-proper-use-of-meteor-wrapasync-on-server) – Brendan Turner Jan 04 '16 at 20:39
  • what kind of error do you see? – MrE Jan 04 '16 at 22:30
  • I've changed my original post to include the suggestions from the answers/comments and am now getting the following error on line 2 above: `Error invoking Method 'ldapLogin': Method not found [404]` – illya Jan 04 '16 at 23:12

1 Answers1

0

Meteor Methods go on the server side

Meteor.call("ldapLogin", username, password, Meteor.user()); calls goes on the Client side (web browser side)

Now, if you are passing parameters in your client side code (username, password...), you should also reference those in your method:

Meteor.methods({
    'processLdapLoginWrapAsync': function(username, password) {
      var syncFunc = Meteor.wrapAsync(processLdapLogin);
      var result = syncFunc(username, password, Meteor.user());

      console.log(result);
    }
  });

(if indeed this is intended from the client of course)

otherwise (if the username/password come from the server side, which I believe is really what you intended here) you should not be passing those parameters from the client and only call:

Meteor.call("ldapLogin") on the client

MrE
  • 19,584
  • 12
  • 87
  • 105