Last active
December 18, 2015 11:09
-
-
Save martintrojer/5773399 to your computer and use it in GitHub Desktop.
futures
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
// map creates a new future that is triggered when the originating future is done | |
scala> future { 42 } map { _ + 1 } map { println(_) } | |
43 | |
res26: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@5427eb13 | |
// flatMap creates a new future that is triggered when the enclosed future is done | |
scala> future { 42 } flatMap { v => future { 1 + v } } map { println(_) } | |
res28: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@9afcbc0 | |
scala> 43 | |
scala> (for { v <- future { 42 }; r <- future { 1 + v } } yield r) onSuccess { case v => println (v) } | |
scala> 43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment