首页 > 解决方案 > 等待一个在一系列承诺中返回真实值的承诺

问题描述

我有一个包含 100 个承诺的承诺数组。我想等待,直到一个承诺以真实的价值实现。另外,我想确保只有 x 个承诺同时运行(设置限制)。

我已经研究过类似的方法bluebird.anybluebird.some但它们没有并发选项。

我该怎么做呢?

标签: javascriptnode.jspromisees6-promise

解决方案


Bluebird promise.map should solve your issue along with the option of concurrency.

promise.map(promiseArray, {concurrency: 4})

The concurrency here basically limits the number of promises running state. If you make concurrency to 1, then they execute serially.


推荐阅读