jt1*_*123 5 synchronous meteor
我如何使用Meteor 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;
}
Run Code Online (Sandbox Code Playgroud)
我想Meteor.call同步运行这两个函数,但我得到undefined了console.log(getGroup);哪个shuold只返回一个对象.
Meteor.wrapAsync是一个服务器端API,旨在包装需要回调作为最后一个参数的Node.js异步函数,以通过使用Futures(Fibers子库)使它们看起来是同步的.(更多相关内容:https://www.discovermeteor.com/blog/wrapping-npm-packages/)
它不打算用于客户端将异步Meteor.call转换为同步调用,因为在浏览器上,Remote Method Invokation调用总是异步的.
长话短说,你根本无法实现你想要做的事情,你必须使用回调并在第一个方法调用的成功回调中嵌套你的第二个方法调用.
| 归档时间: |
|
| 查看次数: |
3536 次 |
| 最近记录: |