Last active
February 19, 2016 16:39
-
-
Save ljwagerfield/7c86ec330219f8970de3 to your computer and use it in GitHub Desktop.
This file contains 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
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.foldLeft(Future.successful(List.empty[Int]))((pf, c) => pf.flatMap(p => Future { | |
Thread.sleep(1000) | |
event("REPORT processing") | |
p ::: List(c * c) | |
})) | |
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