LoginSignup
0
0

More than 5 years have passed since last update.

Scala Futureのawait/readyをもっと楽にする方法

Last updated at Posted at 2018-08-26

前提

ScalaのFuture型のawait/readyの苦痛度が高い。
歴史的経緯・設計者の間隔もあってなぜかFuture型の外にawait/readyが実装されている1

val futureInt = Future(42)

Await.result(futureInt, Duration.Inf)

ソリューション

bigwheel/rich-awaitableを使う。

以下のようにより自然に書ける。

val futureInt = Future(42)
futureInt.safeResult(Duration.Inf)

implicitを使えば毎回最大待機時間を渡す手間も減らせる。

implicit val atMost: Duration = Duration.Inf

val futureInt = Future(42)
futureInt.safeResult

  1. この表現は厳密には語弊がある。詳しくはAwaitable型参照 

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