Last active
January 27, 2017 14:44
-
-
Save eamelink/ff65addbaf3f8e8bf4cf73ac48e5029f to your computer and use it in GitHub Desktop.
Demonstration of scala.concurrent.blocking
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._ | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
// Experiment with and without the `blocking` call in this program! | |
object Test extends App { | |
val x = Future.traverse(1 to 30){ i => | |
Future { | |
println("Starting #" + i) | |
blocking { | |
Thread.sleep(2000) | |
} | |
println("Done with #" + i) | |
i | |
} | |
} | |
Await.ready(x, 1 minute) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment