Created
February 10, 2015 12:32
-
-
Save betandr/188f927e7e3ee7f29290 to your computer and use it in GitHub Desktop.
BLOCKING Futures with Awaits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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