Difference Await.ready and Await.result

前端 未结 3 1035
误落风尘
误落风尘 2021-02-02 07:14

I know this is quite an open ended question and I apologize.

I can see that Await.ready returns Awaitable.type while Await.result

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 07:29

    In general, both are blocking.

    The difference is that Await.ready is blocking until the Future has finished (successful or failed) in given time.

    The only one difference is that ready blocks until the Awaitable is ready and the result does yield the result type T.

    Postscriptum: In practice, if you want to perform some actions like error checking or logging you would take Await.ready(...) if you want to compose the result and throw an error if something goes wrong take Await.result(...).

    As rule of thumb - try to avoid Await.

提交回复
热议问题