This file contains hidden or 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
val uris = Seq( | |
"spray.io", "www.wikipedia.org" | |
//TODO Works well with only 2 URIs, sometimes also with 3 URIs, but does not scale to e.g. 5 URIs! | |
// , "scala-lang.org" | |
// , "doc.akka.io", "public.beuth-hochschule.de/~knabe/", "fb6.beuth-hochschule.de", "stackoverflow.com/questions/tagged/scala" | |
// , "esperanto.de", "tatoeba.org" | |
) | |
//The futures are constructed immediately one after another and are then running. | |
val futures = uris.map(requestProductVersion) |
This file contains hidden or 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 requestProductVersion(uri: String)(implicit system: ActorSystem): Future[ProductVersion] = { | |
val uriCompleted = if(uri.indexOf('/') < 0) uri+'/' else uri | |
import system.dispatcher // execution context for future transformation below | |
val startTime = Platform.currentTime | |
for { | |
response <- IO(Http).ask(HttpRequest(GET, Uri(s"http://$uri"))).mapTo[HttpResponse] | |
_ <- IO(Http) ? Http.CloseAll | |
} yield { | |
val startAtMillis = startTime - system.startTime | |
val durationInMillis = Platform.currentTime - startTime |