Skip to content

Instantly share code, notes, and snippets.

@notyy
Created November 25, 2013 12:32
Show Gist options
  • Save notyy/7640595 to your computer and use it in GitHub Desktop.
Save notyy/7640595 to your computer and use it in GitHub Desktop.
first code block use future promise second only use future
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