Skip to content

Instantly share code, notes, and snippets.

View christophknabe's full-sized avatar

Christoph Knabe christophknabe

View GitHub Profile
@christophknabe
christophknabe / FutureCrawlMain.scala
Created June 24, 2014 13:49
Collecting ProductVersions of several servers.
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)
@christophknabe
christophknabe / RequestLevelApiDemo.scala
Last active August 29, 2015 14:02
Getting the Future of the ProductVersion of the server offering the requested URI
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