Combine elasticsearch js with bluebird
Combine elasticsearch js with bluebird
我开始与node.js, 蓝鸟承诺框架。我正试图将其与elasticsearch javascript驱动程序集成。我设法使其工作使用以下代码。我想知道这是不是开始承诺的最好方式。我省略了和步骤中调用的函数。
var esPromise = client.search({
index: "myindex",
searchType: "count",
body: {
aggs: {
allIp: {
terms: {
field: "ip",
size: 1000,
order: {
_term: "asc"
}
}
}
}
}
});
new Promise(function (resolve, reject) {
esPromise.then(resolve, reject);
})
.then(extract_ips_from_aggs)
.then(sort_ips)
.then(log_ips)
.catch(function (error) {
console.log(error);
});
您可以覆盖内部使用的延迟对象,如:
var Bluebird = require('bluebird');
var client = new elasticsearch.Client({
defer: function () {
// for older Bluebird
// return Bluebird.defer();
var resolve, reject;
var promise = new PromiseImpl(function() {
resolve = arguments[0];
reject = arguments[1];
});
return {
resolve: resolve,
reject: reject,
promise: promise
};
}
});
默认情况下,文档声明它使用ES6 Promise。
阅读更多配置信息
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- 承诺在非节点式回调上使用Bluebird
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Bluebird unhandled Error with emit NodeJS
- Promisifying bcrypt-nodejs with Bluebird
- Combine elasticsearch js with bluebird
- Promisify Nodemailer with bluebird?