Javascript 带有Meteor.wrapAsync()的菊花链NPM包函数

Javascript 带有Meteor.wrapAsync()的菊花链NPM包函数,javascript,node.js,asynchronous,meteor,npm,Javascript,Node.js,Asynchronous,Meteor,Npm,我正在尝试使用meteor应用程序中的节点包。在本机节点中,我需要将调用菊花链连接在一起,如下所示: return client.auth(req.session.token, req.session.sec).user("_SELF_").find(function(err, body, headers) { if (err) { console.log(err); } if (body) { console.dir(body); }

我正在尝试使用meteor应用程序中的节点包。在本机节点中,我需要将调用菊花链连接在一起,如下所示:

return client.auth(req.session.token, req.session.sec).user("_SELF_").find(function(err, body, headers) {
    if (err) {
      console.log(err);
    }
    if (body) {
      console.dir(body);
    }
    if (body) {
      return res.send(body.results[0]);
    }
  });
我试过几件事都没有成功。例如:

  var authSync = Meteor.wrapAsync(client.auth, client);
  return authSync(req.session.token, req.session.sec).user("_SELF_").find(function(err, body, headers) {
        if (err) {
          console.log(err);
        }
        if (body) {
          console.dir(body);
        }
        if (body) {
          return res.send(body.results[0]);
        }
      });

如果我错了,请纠正我,但似乎只有
find()
方法是异步的

因此,
client.auth(req.session.token,req.session.sec).user(“\u SELF”)
将使用
find()
方法返回一些对象,这是您真正需要包装的对象

var user = client.auth(req.session.token, req.session.sec).user("_SELF_");
var findAsync = Meteor.wrapAsync(user.find, user);
try {
  var body = findAsync();
  return res.send(body.results[0]);
} catch(e) {
  console.log(e);
}
它将返回任何
结果。发送(…)
返回

回调不符合标准的error-first回调签名(
function(error,result){}
),但是它应该仍然可以工作,尽管我认为没有任何方法可以检索第三个参数(
headers

如果您是在方法内部执行此操作,那么使用直接未来可能更合适