流星wrapAsync语法 [英] Meteor wrapAsync syntax

查看:49
本文介绍了流星wrapAsync语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用流星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,而shuold只是返回了一个对象.

I want to run these two Meteor.callfunctions synchronosly but I get undefined on console.log(getGroup); which shuold just return an object.

推荐答案

Meteor.wrapAsync是服务器端API,旨在包装需要回调作为最后一个参数的Node.js异步函数,以使其通过使用来同步显示. Future s,光纤子库. (有关更多信息,请参见: https://www.discovermeteor.com/blog/wrapping-npm-packages/)

Meteor.wrapAsync is a server-side API designed to wrap Node.js asynchronous functions requiring a callback as last argument, to make them appear synchronous through the use of Futures, a Fibers sub-library. (more on this here : https://www.discovermeteor.com/blog/wrapping-npm-packages/)

不打算在客户端将异步Meteor.call转换为同步调用,因为在浏览器上,远程方法调用"调用始终是异步的.

It is not intended to be used client-side to turn asynchronous Meteor.call into a synchronous call because on the browser, Remote Method Invokation calls are ALWAYS asynchronous.

长话短说,您根本无法实现您要执行的操作,您必须使用回调并将第二个方法调用嵌套在第一个方法调用的成功回调中.

Long story short, you simply cannot achieve what you're trying to do, you have to use callbacks and nest your second method call inside the success callback of your first method call.

这篇关于流星wrapAsync语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆