是否有适当的方法来承诺 arangojs?

Is there a proper way to promisify arangojs?

我想在我的项目中使用 arangojs 3.4.2。从 3.0 开始,驱动程序不再使用 promises。 在尝试了几个库来承诺驱动程序之后,我没有成功(bluebird,promisify-node ...):每次驱动程序 returns 一个新实例,该实例未被承诺,我必须再次承诺新实例与承诺一起使用:

var Promise=require('bluebird');
var arango=require('arangojs');
db=Promise.promisifyAll(new arango("http://localhost:8529"));
/*db is promisified properly*/
testdb=db.databaseAsync('test').then(function(testInstance){
    /*
    the testInstance returned by the driver is not promisified
    to use it with promises i've to promisify again
    */
})

有办法实现吗?

没错。

如果要promisify驱动中所有对象的所有方法,需要直接promisify原型的方法:

var Database = require('arangojs/lib/Database');
Promise.promisifyAll(Database.prototype);

var db = new Database('http://localhost:8529');
db.databasesAsync().then(function (databases) {
  databases.forEach(function (database) {
    assertTrue(typeof database.databaseAsync === 'function');
  });
});

As of version 3.5, if the global Promise constructor is defined when an asynchronous function is called, the function will also return a promise.

https://github.com/arangodb/arangojs