Skip to content

Instantly share code, notes, and snippets.

@pchlupacek
Last active August 4, 2017 16:59
Show Gist options
  • Save pchlupacek/6c47debb4c7c2725374608ac054045a7 to your computer and use it in GitHub Desktop.
Save pchlupacek/6c47debb4c7c2725374608ac054045a7 to your computer and use it in GitHub Desktop.
Concurrent clients with fs2-http
// source of uris, may be for example file, or another http server, db ...
val sourceOfUris: Stream[F, Uri] = ???
// max requests to process in parallel
val maxConcurrent: Int = ???
val responses : Stream[F, Stream[F, HttpResponse[F]]] =
http.client[Task]().flatMap { client =>
sourceOfUris map { uri => client.request(HttpRequest.get[F](uri))}
}
val sourceOfBodys: Stream[F, String] =
concurrent.join(maxConcurrent)(response map { _ flatMap { resp =>
resp.bodyAsString // but you could consume here bytes, stream, etc... see the doc
}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment