Skip to content

Instantly share code, notes, and snippets.

@vkobel
Created April 23, 2013 19:43
Show Gist options
  • Save vkobel/5446764 to your computer and use it in GitHub Desktop.
Save vkobel/5446764 to your computer and use it in GitHub Desktop.
Simple use of akka futures (now part of scala library)
package akkaActors
import scala.concurrent.Await // enable awaiting a future
import scala.concurrent.duration._ // enable convert in to ms n.seconds
import scala.concurrent.Future // Future function
import scala.concurrent.ExecutionContext.Implicits.global // import global execution context (implicit way)
object futureTest extends App {
// Create and begin execution of the Future
val future = Future {
Thread.sleep(5000)
"Yay!"
}
for (i <- 1 to 10) {
Thread.sleep(450)
println(i)
}
// Await the result
val res = Await.result(future, 10 seconds)
println(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment