Created
April 23, 2013 19:43
-
-
Save vkobel/5446764 to your computer and use it in GitHub Desktop.
Simple use of akka futures (now part of scala library)
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
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