【发布时间】:2014-06-02 01:56:44
【问题描述】:
如果我有一个数组:
['one.html','two.html','three.html']
我如何分解该数组,对其应用一系列承诺,然后将其重新组合在一起?目前我的代码是这样的:
Promise.map(['one','two','three'], function(i) {
dbQuery('SELECT ' + i);
}).then(function(results) {
// This has an array of DB query results
});
我在想象这样的事情:
Promise.map(['one','two','three'], function(i) {
dbQuery('SELECT ' + i);
})
.explode()
.then(function(result) {
// Individual result
})
.combine()
.then(function(results) {
// Now they're back as an array
});
现在,我知道 Bluebird 没有这些功能,所以我想知道正确的 Promise-y 方法是什么?
【问题讨论】:
标签: javascript promise bluebird