如何使用流星wrapAsync
下面是我想要做的事
if (tempTreatment.groupId === undefined) {
// create new group
Meteor.wrapAsync(Meteor.call('createTreatmentGroup', salon, tempTreatment.groupName, tempTreatment.groupName));
// get group id
var getGroup = Meteor.wrapAsync(Meteor.call('getTreatmentGroup', salon, tempTreatment.groupName));
console.log(getGroup);
tempTreatment.groupId = getGroup._id;
}
我想同步运行这两个Meteor.call
函数,但是我在console.log(getGroup);
上得到了undefined
,它只返回一个对象。
发布于 2014-09-26 11:34:49
Meteor.wrapAsync
是一个服务器端API,旨在封装需要回调的Node.js异步函数作为最后一个参数,通过使用FibersFibers子库使它们看起来是同步的。(在这里有更多的信息:https://www.discovermeteor.com/blog/wrapping-npm-packages/)
不打算使用客户端将异步Meteor.call
转换为同步调用,因为在浏览器上,远程方法Invokation调用总是异步的。
长话短说,你根本无法实现你想要做的事情,你必须使用回调并在你的第一个方法调用的成功回调中嵌套你的第二个方法调用。
https://stackoverflow.com/questions/26058205
复制相似问题