Skip to content

Instantly share code, notes, and snippets.

@eamelink
Last active January 27, 2017 14:44
Show Gist options
  • Save eamelink/ff65addbaf3f8e8bf4cf73ac48e5029f to your computer and use it in GitHub Desktop.
Save eamelink/ff65addbaf3f8e8bf4cf73ac48e5029f to your computer and use it in GitHub Desktop.
Demonstration of scala.concurrent.blocking
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