They both block until the future completes, the difference is just their return type.
The difference is useful when your Future
throws exceptions:
def a = Future { Thread.sleep(2000); 100 }
def b = Future { Thread.sleep(2000); throw new NullPointerException }
Await.ready(a, Duration.Inf) // Future(Success(100))
Await.ready(b, Duration.Inf) // Future(Failure(java.lang.NullPointerException))
Await.result(a, Duration.Inf) // 100
Await.result(b, Duration.Inf) // crash with java.lang.NullPointerException
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…