@RyeWiskey

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

非同期で3つのFutureを実行させてそれぞれの答えを出したい

scalaを勉強しているのですが非同期で3つのFutureを実行させてそれぞれの答えを出したい
しかしうまくいきません

main.scala
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.util.{Success, Failure}
import scala.concurrent.ExecutionContext.Implicits.global
def f_Fail(): Future[String] = Future {
      Thread.sleep(1000)
      throw new RuntimeException("わざと失敗")
    }
def f_success(): Future[String] = Future {
      Thread.sleep(1000)
      "future!"
    }
    val f1 = f_success()
    val f2 = f_success()
    val f3 = f_Fail()
    val future =for {
        n <- f1
        m <- f2
        p <- f3
    } yield n+"\n"+m+"\n"+p
Await.ready(future,Duration.Inf).value.get match {
      case Success(v) => println(v)
      case Failure(e) => println("not found")
    }

期待した結果

"future!"
"future!"
"not found"

実際の結果

"not found"

0 likes

No Answers yet.

Your answer might help someone💌