javascript - 等待一个在一系列承诺中返回真实值的承诺
问题描述
我有一个包含 100 个承诺的承诺数组。我想等待,直到一个承诺以真实的价值实现。另外,我想确保只有 x 个承诺同时运行(设置限制)。
我已经研究过类似的方法bluebird.any
,bluebird.some
但它们没有并发选项。
我该怎么做呢?
解决方案
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.
推荐阅读
- django - Django:如何将我的基于函数的视图重新创建为(通用编辑)基于类的视图
- docker - 在 Docker 中使用 Unicorn Flask 配置 Nginx
- cordova - MS AppCenter CodePush 未更新
- jquery - 尝试使用 OR 逻辑将同位素过滤器与分页集成
- python - 如何在包含分类变量的 Pandas 数据框中仅贬低数字列?
- javascript - 处理“无法在未安装的组件上调用 setState”反应警告的最佳方法
- python-2.7 - 使用#egg pip 安装本地存储库
- python - 如何连接具有不连续 x 轴边界的 matplotlib LineCollection 段?
- javascript - 根据星期几向元素添加类
- matlab - 如何解决我的代码中的“if 语句”问题?