Created
November 25, 2013 12:32
-
-
Save notyy/7640595 to your computer and use it in GitHub Desktop.
first code block use future promise
second only use future
This file contains hidden or 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.{ future, promise } | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val p = promise[String] | |
val f = p.future | |
val producer = future { | |
println("producing") | |
Thread.sleep(1000) | |
val r = "produced" | |
p success r | |
Thread.sleep(1000) | |
println("producer ends") | |
} | |
val consumer = future { | |
println("listening to producer") | |
f onSuccess { | |
case r => println("got result from producer:" + r) | |
} | |
Thread.sleep(2000) | |
println("consumer ends") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment