Skip to Content
Scala Reactive Programming
book

Scala Reactive Programming

by Rambabu Posa
February 2018
Intermediate to advanced
552 pages
13h 46m
English
Packt Publishing
Content preview from Scala Reactive Programming

Scala Async API

The Scala Async object is defined in the scala.async package. It has the following two functions:

object Async {  def async[T](body: => T)(implicit execContext: ExecutionContext): Future[T]  def await[T](awaitable: Future[T]): T}

The async function is similar to the apply function of the Future object. It takes an asynchronous computation as input and returns a Future object.

The await function takes a future object as input and returns that Future's value. It does not block the underlying thread that executes that computation logic.

An example of the Scala Async API:

  1. Create a Scala SBT Project, scala-async-app.
  2. Add the Scala Async library to the build.sbt file:
      name := "scala-async-app"      version := "1.0.0" scalaVersion := ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Scala Programming Projects

Scala Programming Projects

Mikael Valot, Nicolas Jorand
Learning Scala

Learning Scala

Jason Swartz
Functional Programming in Scala

Functional Programming in Scala

Runar Bjarnason, Paul Chiusano

Publisher Resources

ISBN: 9781787288645Supplemental Content