Created
February 19, 2016 16:33
-
-
Save ljwagerfield/0e4cbb323d9858e5dc55 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.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