Skip to content

Instantly share code, notes, and snippets.

@betandr
Created February 10, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betandr/188f927e7e3ee7f29290 to your computer and use it in GitHub Desktop.
Save betandr/188f927e7e3ee7f29290 to your computer and use it in GitHub Desktop.
BLOCKING Futures with Awaits
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Success, Failure}
val f1: Future[String] = Future {
Thread.sleep(200)
"done 1..."
}
val f2: Future[String] = Future {
Thread.sleep(200)
"done 2..."
}
Await.result(f1, 10 seconds)
Await.result(f2, 10 seconds)
f1 onComplete{
case Success(result) => println(result)
case Failure(t) => println("An error has occured: " + t.getMessage)
}
f2 onComplete{
case Success(result) => println(result)
case Failure(t) => println("An error has occured: " + t.getMessage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment