Skip to content

Instantly share code, notes, and snippets.

@eamelink
Last active January 27, 2017 14:44

Revisions

  1. eamelink revised this gist Jan 27, 2017. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions blocking.scala
    Original file line number Diff line number Diff line change
    @@ -7,13 +7,14 @@ object Test extends App {

    val x = Future.traverse(1 to 30){ i =>
    Future {
    println("Starting " + i)
    blocking {
    Thread.sleep(2000)
    }
    println("Starting #" + i)
    blocking {
    Thread.sleep(2000)
    }
    println("Done with #" + i)
    i
    }
    }

    println(Await.result(x, 1 minute))
    Await.ready(x, 1 minute)
    }
  2. eamelink created this gist Jan 27, 2017.
    19 changes: 19 additions & 0 deletions blocking.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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)
    }
    i
    }
    }

    println(Await.result(x, 1 minute))
    }