Scala Future examples

We have discussed lots of theory so far. It's good to start developing some examples to understand the Scala Future API. Let's start now with the Scala Hello World Future App:

  1. Create a Scala SBT project in your favorite IDE (mine is IntelliJ IDEA):
      Project Name: scala-future-app

build.sbt:

      name := "scala-future-app" 
      version := "1.0" 
      scalaVersion := "2.12.3" 
  1. Create a Scala App:
      object ScalaFutureHelloWorldApp extends App{      }
  1. Create a HelloWorld Future Object:

ScalaFutureHelloWorldApp.scala:

      import scala.concurrent.Future      object ScalaFutureHelloWorldApp extends App{        val helloWordlFuture = Future("Hello World")      }
  1. When we run this program, we can observe the following error:
[error] .../scala-future- app/src/main/scala/com/packt/publishing/concurrent/future/ScalaFutureHelloWolrdApp.scala:8: ...

Get Scala Reactive Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.