现在几乎每个节点包都有回调api。如果我正在编写包装器,例如ORM,那该怎么办?
const Promise = require('bluebird');
const mongo = Promise.promisifyAll(require('mongodb'));
class ORM {
constructor(mongoUrl) {
this.db = mongo.connectAsync(mongoUrl);
}
collection(name) {
return this.db.then((db) => {
return db.collectionAsync(name);
});
}
}
这是正确的方法吗?