Skip to content

Instantly share code, notes, and snippets.

@ljwagerfield
Created February 19, 2016 16:33
Show Gist options
  • Save ljwagerfield/0e4cbb323d9858e5dc55 to your computer and use it in GitHub Desktop.
Save ljwagerfield/0e4cbb323d9858e5dc55 to your computer and use it in GitHub Desktop.
def run() = {
import scala.concurrent.{ blocking, ExecutionContext, Future }
implicit val ec = ExecutionContext.fromExecutor(java.util.concurrent.Executors.newFixedThreadPool(1))
val startTime = System.nanoTime()
def event(name: String) =
Console.println(s"t=${(System.nanoTime - startTime) / 1000000000}s | $name")
event("REPORT request RCVD")
val candidates = 1 to 10
val calculations = candidates.map(c => Future {
Thread.sleep(1000)
event("REPORT processing")
c * c
})
Future.sequence(calculations).map { calcs =>
event("REPORT response SENT")
}
event("PING request RCVD")
Future {
event("PING response SENT")
}
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment