Object

scala.async

Async

Related Doc: package async

Permalink

object Async

Async blocks provide a direct means to work with scala.concurrent.Future.

For example, to use an API that fetches a web page to fetch two pages and add their lengths:

import ExecutionContext.Implicits.global
import scala.async.Async.{async, await}

def fetchURL(url: URL): Future[String] = ...

val sumLengths: Future[Int] = async {
  val body1 = fetchURL("http://scala-lang.org")
  val body2 = fetchURL("http://docs.scala-lang.org")
  await(body1).length + await(body2).length
}

Note that in the following program, the second fetch does *not* start until after the first. If you need to start tasks in parallel, you must do so before await-ing a result.

val sumLengths: Future[Int] = async {
  await(fetchURL("http://scala-lang.org")).length + await(fetchURL("http://docs.scala-lang.org")).length
}
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Async
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. macro def async[T](body: ⇒ T)(implicit execContext: ExecutionContext): Future[T]

    Permalink

    Run the block of code body asynchronously.

    Run the block of code body asynchronously. body may contain calls to await when the results of a Future are needed; this is translated into non-blocking code.

  6. def await[T](awaitable: Future[T]): T

    Permalink

    Non-blocking await the on result of awaitable.

    Non-blocking await the on result of awaitable. This may only be used directly within an enclosing async block.

    Internally, this will register the remainder of the code in enclosing async block as a callback in the onComplete handler of awaitable, and will *not* block a thread.

    Annotations
    @compileTimeOnly( ... )
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  18. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped