ios - 向数组添加 Promise 并防止它们自动解析
问题描述
我希望将任意数量的 Promise 添加到数组中,并让它们在某个时候一个接一个地依次解决。快速伪 swift-code 将是(不沉迷于如何顺序调用承诺):
var someArray: [Promise<Bool>] = [first, second, third, fourth, ...]
...
someArray.append(contentsOf: getMorePromises())
...
firstly {
...
}.then {
// use someArray here and compose a single Promise
// that links to the next element in the array using .then
}
我遇到的问题是,someArray
甚至在我到达firstly
. 如何防止这种情况发生,以便我在数组中保留承诺,并且只有在其中一个then
部分内时才让它们解决?
解决方案
我已经想通了。在将它们添加到数组之前将它们包装在闭包中,然后在将它们拉出数组以使其触发时解开闭包。
推荐阅读
- javascript - 如何在 Nodejs 中调用祖父方法
- laravel - Laravel - 我需要在哪里放置我的 sum()
- python - 无法在python中导入破折号
- javascript - 尝试使用 highcharts.js 在分组箱形图上叠加散点图
- python - Tensorflow 和 Celeron G1840 WIn 10 安装
- r - 在 R 中创建函数以进行子集化并运行 AUDPC 分析
- conda - Conda 后链接脚本不运行
- java - Java:“If”语句中 AND 之后的 OR 运算符
- wordpress - 如何在标准分页中隐藏删除下一个和上一个按钮
- vba - 查找所选单元格上方的第一个非空白行