简体   繁体   English

有正确的方法来传播arangojs吗?

[英]Is there a proper way to promisify arangojs?

I'd like to use arangojs 3.4.2 in my project. 我想在我的项目中使用arangojs 3.4.2。 Since 3.0 there are no promises used by the driver. 从3.0开始,驱动程序不使用任何承诺。 After trying several libs to promisify the driver i have no success (bluebird,promisify-node...): each time the driver returns a new instance that instance is not promisified, and i have to promisify the new instance again to use with promises: 在尝试了多个lib来使驱动程序传播后,我没有成功(bluebird,promisify-node ...):每次驱动程序返回一个新的实例时,该请求都不会被传播,而我必须再次对新的实例进行传播,以便与promises一起使用。 :

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
    */
})

Is there a way to achieve this? 有没有办法做到这一点?

That is correct. 那是对的。

If you want to promisify all the methods of all the objects in the driver, you need to promisify the prototypes' methods directly: 如果要使驱动程序中所有对象的所有方法均化,则需要直接使原型的方法均化:

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. 从3.5版开始,如果在调用异步函数时定义了全局Promise构造函数,则该函数还将返回一个promise。

https://github.com/arangodb/arangojs https://github.com/arangodb/arangojs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM