Meteor.js Aysnc没有返回结果继续加载

时间:2017-08-08 07:35:45

标签: node.js meteor

这里,我调用方法来获取异步方法中的Quickblox结果。虽然我在控制台打印值我可以得到它,但应用程序继续加载不返回结果。

服务器端:

Meteor.methods({
  allquickbloxusers_Methods: function(){
    var params = {login: ["99999"]};

    var asyncCall = QB1.users.get(params, Meteor.bindEnvironment(function(err, QBuser) {
        if(QBuser) {
            return QBuser;  
            } else {
                return err;
            }       
        }));

    var syncCall = Meteor.wrapAsync(asyncCall);
    var res = syncCall();

    // now you can return the result to client.
    return res;  
  }
});

1 个答案:

答案 0 :(得分:0)

使用Meteor.wrapAsync想要传递实际函数,而不是被调用函数的结果。像这样:

Meteor.methods({
  allquickbloxusers_Methods: function(){
    var params = {login: ["99999"]};

    var syncCall = Meteor.wrapAsync(QB1.users.get)

    var res = syncCall(params);

    // now you can return the result to client.
    return res;  
  }
});

基本上wrapAsync会为您提供一个新功能,您可以使用原始功能的参数调用该功能。

了解这一点,您可以使功能更简洁:

Meteor.methods({
  allquickbloxusers_Methods: function(){
    var params = {login: ["99999"]};

    return Meteor.wrapAsync(QB1.users.get)(params)
  }
});
相关问题