【发布时间】:2026-01-31 09:20:02
【问题描述】:
我正在将一个项目从 Q 迁移到 bluebird。 在这个项目中,Q.invoke 被大量使用。
例如在这样的中心方法中:
repo.count = function(entity,query) { // entity is a mongoose model
var command = query = entity.find(query).count();
return Q.ninvoke(command, 'exec');
};
重构此代码并返回相同“种类”承诺的最佳蓝鸟方式是什么? 阅读蓝鸟文档,似乎 promisifyAll 似乎是正确方向的一点。现在我有这个工作,但使呼叫阻塞:
repo.count = function*(entity,query) {
entity = bluebird.promisifyAll(entity); // this needs to be moved somewhere central
return yield entity.find(query).count();
};
【问题讨论】:
标签: node.js mongoose promise q bluebird