Created
October 25, 2013 04:00
-
-
Save ryanlecompte/7149289 to your computer and use it in GitHub Desktop.
future flatmapping with no stack blowing
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
scala> def loop(f: Future[Int]): Future[Int] = { | |
| f.flatMap { i => | |
| if (i == 1e6) Future.successful(i) | |
| else loop(future(i + 1)) | |
| } | |
| } | |
scala> val f = loop(future(1)) | |
scala> Await.result(f, Duration.Inf) | |
res1: Int = 1000000 | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment