Scala: completing a Future when other Futures are completed

会有一股神秘感。 提交于 2019-12-23 02:03:44

问题


I have references to n Future instances f1,.....fn. Is it possible to use Future.apply to create a Future that would complete only when at least one of the n Futures completes, without constantly checking their completion status, but instead by some more efficient way, maybe a callback?


回答1:


Future.firstCompletedOf(Seq(f1, ..., fn))

Asynchronously and non-blockingly returns a new Future to the result of the first future in the list that is completed.



来源:https://stackoverflow.com/questions/47068342/scala-completing-a-future-when-other-futures-are-completed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!