Scala waiting for sequence of futures

后端 未结 6 2309
野的像风
野的像风 2020-12-04 15:39

I was hoping code like follows would wait for both futures, but it does not.

object Fiddle {
  val f1 = Future {
    throw new Throwable(\"baaa\") // emulat         


        
6条回答
  •  無奈伤痛
    2020-12-04 16:11

    A Future produced by Future.sequence completes when either:

    • all the futures have completed successfully, or
    • one of the futures has failed

    The second point is what's happening in your case, and it makes sense to complete as soon as one of the wrapped Future has failed, because the wrapping Future can only hold a single Throwable in the failure case. There's no point in waiting for the other futures because the result will be the same failure.

提交回复
热议问题