Created
February 3, 2015 11:38
-
-
Save betandr/8ce4556ee45e54dca989 to your computer and use it in GitHub Desktop.
Futures
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.util.{Success, Failure} | |
import scala.concurrent.Future | |
import scala.util.Random | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object Futures extends App { | |
val f: Future[String] = Future { | |
Thread.sleep(Random.nextInt(200)) | |
"done..." | |
} | |
f onComplete { | |
case Success(result) => println(result) | |
case Failure(t) => println("An error has occured: " + t.getMessage) | |
} | |
val result = f | |
Thread.sleep(1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment