Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Created December 2, 2013 16:59
Show Gist options
  • Select an option

  • Save akimboyko/7752665 to your computer and use it in GitHub Desktop.

Select an option

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
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