简体   繁体   中英

Meteor.wrapAsync() not working

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM