Created
December 2, 2013 16:59
-
-
Save akimboyko/7752665 to your computer and use it in GitHub Desktop.
Producer/Consumer from section "Futures and Promises" http://docs.scala-lang.org/overviews/core/futures.html
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[T] | |
| val f = p.future | |
| val producer = future { | |
| val r = produceSomething() | |
| p success r | |
| continueDoingSomethingUnrelated() | |
| } | |
| val consumer = future { | |
| startDoingSomething() | |
| f onSuccess { | |
| case r => doSomethingWithResult() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment