流星服务器

时间:2016-11-29 13:38:33

标签: javascript node.js meteor soap node-soap

我正在使用vpulim:node-soap运行soap服务器。

我的流星服务器启动包含其他各种代码:

  authRequestOperation: function(args,cb,headers,req) {
      console.log(args);
      var authResponceObject = {};
      var futureAuthResponse = new Future();
      Fiber(function(){
        if(collectorUsers.findOne({username: args.username})){
          console.log("Found User");
          authResponceObject = {
            username: args.username,
            nonce: Random.id()
          };
          console.log("authResponceObject is: " + JSON.stringify(authResponceObject,null,4));
          console.log("futureAuthResponse returning...");
          futureAuthResponse.return(authResponceObject);
        }
        // console.log("futureAuthResponse waiting...");
        // return futureAuthResponse.wait();


      }).run();
      console.log("authResponceObject after fiber is: " + JSON.stringify(authResponceObject,null,4));
      return authResponceObject;
  },

我想做的是:

  1. 我从客户端收到一个用户对象。
  2. 我检查用户是否在mongodb中
  3. 如果用户在场,请准备响应对象
  4. 使用响应对象回复客户端。
  5. 我有1.工作。但是,它是异步调用的dute,2,3,4的顺序搞砸了。

    现在发生的事情是:

    1. 接收客户对象
    2. 返回响应对象(为空)
    3. 检查mongo
    4. 准备响应对象。
    5. 我没有使用Meteor.methods来实现上述目标。 如何以正确的方式完成这项工作?我试过在wrapAsyncfiber/future附近玩杂耍,但是遇到了死胡同。

1 个答案:

答案 0 :(得分:1)

我相信Meteor.bindEnvironment可以解决您的问题,请尝试以下代码:

{
  // ...
  authRequestOperation: Meteor.bindEnvironment(function(args, cb, headers, req) {
    console.log(args);
    var authResponceObject = {};

    if (collectorUsers.findOne({username: args.username})) {
      console.log("Found User");
      authResponceObject = {
        username: args.username,
        nonce: Random.id()
      };
      console.log("authResponceObject is: " + JSON.stringify(authResponceObject, null, 4));
    }


    return authResponceObject;
  }),
  // ...
}