问题
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