com.thoughtworks.dsl.keywords
Await is a Keyword to extract value from a scala.concurrent.Future.
This keyword is available in functions whose return types are Future, domains.task.Task, or any exception aware continuations as (_ !! Throwable !! _).
(_ !! Throwable !! _)
import scala.concurrent.Future
杨博 (Yang Bo)
Given a Future:
val myFuture40 = Future { 40 }
You can Await the Future in another Future
import scala.concurrent.Future def myFuture42 = Future { !Await(myFuture40) + 2 }
A Future can be converted to a domains.task.Task with the help of Await.
import com.thoughtworks.dsl.domains.task._ import com.thoughtworks.dsl.keywords._ val myTask = Task { !Await(myFuture42) }
Then a domains.task.Task can be converted back to a scala.concurrent.Future via domains.task.Task.toFuture.
val myAssertionTask = Task { !Shift(myTask) should be(42) } Task.toFuture(myAssertionTask)
!Await can be used together with try / catch / finally.
!Await
try
catch
finally
def recoverFuture = Future { "Oh" } def exceptionalFuture = Future[String] { throw new IllegalStateException("No!") } def myFuture = Future { (try { !Await(exceptionalFuture) } catch { case e: IllegalStateException => s"${!Await(recoverFuture)} ${e.getMessage}" }) should be("Oh No!") } myFuture
An alias to cpsApply.
Await is a Keyword to extract value from a scala.concurrent.Future.
This keyword is available in functions whose return types are Future, domains.task.Task, or any exception aware continuations as
(_ !! Throwable !! _)
.import scala.concurrent.Future
Author:
杨博 (Yang Bo)
Given a Future:
You can Await the Future in another Future
A Future can be converted to a domains.task.Task with the help of Await.
Then a domains.task.Task can be converted back to a scala.concurrent.Future via domains.task.Task.toFuture.
!Await
can be used together withtry
/catch
/finally
.