Class/Object

com.thoughtworks.dsl.keywords

Await

Related Docs: object Await | package keywords

Permalink

final case class Await[Value](future: Future[Value]) extends AnyVal with Keyword[Await[Value], Value] with Product with Serializable

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)

Source
Await.scala
Examples:
  1. Other keywords, including Return or Get, can be used together with Await

    import com.thoughtworks.dsl.keywords.{Get, Return}
    val buffer = new StringBuffer
    def recoverFuture = Future {
      buffer.append("Oh")
    }
    def exceptionalFuture = Future[StringBuffer] {
      throw new IllegalStateException("No")
    }
    def myFuture: Char => Future[StringBuffer] = !Return {
      try {
        !Await(exceptionalFuture)
      } catch {
        case e: IllegalStateException =>
          !Await(recoverFuture)
          buffer.append(!Get[Char])
          buffer.append(e.getMessage)
      } finally {
        buffer.append("!")
      }
    }
    myFuture(' ').map(_.toString should be("Oh No!"))
  2. ,
  3. !Await can be used together with try / catch / finally.

    val buffer = new StringBuffer
    def recoverFuture = Future {
      buffer.append("Oh")
    }
    def exceptionalFuture = Future[StringBuffer] {
      throw new IllegalStateException("No")
    }
    def myFuture = Future {
      try {
        !Await(exceptionalFuture)
      } catch {
        case e: IllegalStateException =>
          !Await(recoverFuture)
          buffer.append(' ')
          buffer.append(e.getMessage)
      } finally {
        buffer.append("!")
      }
    }
    myFuture.map(_.toString should be("Oh No!"))
  4. ,
  5. 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)
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Await
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Keyword
  7. AnyVal
  8. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Await(future: Future[Value])

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to any2stringadd[Await[Value]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Await[Value], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to ArrowAssoc[Await[Value]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. final def apply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[Await[Value], Domain, Value]): Domain

    Permalink

    An alias to cpsApply.

    An alias to cpsApply.

    Definition Classes
    Keyword
    Annotations
    @inline()
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. final def cpsApply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[Await[Value], Domain, Value]): Domain

    Permalink
    Definition Classes
    Keyword
    Annotations
    @inline()
  9. def ensuring(cond: (Await[Value]) ⇒ Boolean, msg: ⇒ Any): Await[Value]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to Ensuring[Await[Value]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: (Await[Value]) ⇒ Boolean): Await[Value]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to Ensuring[Await[Value]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean, msg: ⇒ Any): Await[Value]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to Ensuring[Await[Value]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: Boolean): Await[Value]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to Ensuring[Await[Value]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to StringFormat[Await[Value]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  14. val future: Future[Value]

    Permalink
  15. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. final def unary_!: Value

    Permalink
    Definition Classes
    Keyword
    Annotations
    @shift() @compileTimeOnly( ... )
  18. def [B](y: B): (Await[Value], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Await[Value] to ArrowAssoc[Await[Value]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Keyword[Await[Value], Value]

Inherited from AnyVal

Inherited from Any

Inherited by implicit conversion any2stringadd from Await[Value] to any2stringadd[Await[Value]]

Inherited by implicit conversion StringFormat from Await[Value] to StringFormat[Await[Value]]

Inherited by implicit conversion Ensuring from Await[Value] to Ensuring[Await[Value]]

Inherited by implicit conversion ArrowAssoc from Await[Value] to ArrowAssoc[Await[Value]]

Ungrouped