Skip to content

Instantly share code, notes, and snippets.

@betandr
Created February 3, 2015 11:38
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/8ce4556ee45e54dca989 to your computer and use it in GitHub Desktop.
Save betandr/8ce4556ee45e54dca989 to your computer and use it in GitHub Desktop.
Futures
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