0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Scala] for expression の中で Future を並列に走らせる方法

Posted at

ダメな方法

for {
    res1 <- Future.value(1)
    res2 <- Future.value(2)
} yield res1 + res2

良い方法

val f1 <- Future.value(1)
val f2 <- Future.value(2)

for {
    res1 <- f1
    res2 <- f2
} yield res1 + res2

Futureは初期化した時点で実行が開始するので、この書き方なら2つのFutureは並列に実行される。

Ref

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?