var total = 7
var complete_total = 0
fun start(){
complete_total = 0
for(i in 0-7){
// 异步任务
task.run(object:Callback(){
...
final(){
complete_total++
if(complete_total == total){
completeAll()
}
}
})
}
}
fun completeAll(){
// 全部执行完毕
}
大概就会上面的代码
但是打印complete_total,打印了7次
1==7
2==7
3==7
4==7
4==7
5==7
6==7
请问下这是什么原因吗?
有什么办法保证全部任务执行完毕后再回调吗?
题主问题可以使用
Zip操作符
来解决,而且能规避题主自己回答中缺少异常处理的问题。http://reactivex.io/documenta...