Scala: completing a Future when other Futures are

2019-05-30 15:13发布

问题:

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.



标签: scala future