我正在使用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.工作。但是,它是异步调用的dute,2,3,4的顺序搞砸了。
现在发生的事情是:
我没有使用Meteor.methods来实现上述目标。
如何以正确的方式完成这项工作?我试过在wrapAsync
和fiber/future
附近玩杂耍,但是遇到了死胡同。
答案 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;
}),
// ...
}