Await Scala Futures

Here’s Scala example code that creates 100 Futures and waits forĀ all of them to complete. This is using theĀ global ExecutionContext.

import scala.concurrent.{Future, Await, future}
import scala.concurrent.duration.Duration

object WaitForAllFutures extends App {

    val futures = (1 to 100).map { i =>
      future {
        println(s"Future $i done.")

    Await.result(Future.sequence(futures), Duration.Inf)

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *