Last active
August 4, 2017 16:59
-
-
Save pchlupacek/6c47debb4c7c2725374608ac054045a7 to your computer and use it in GitHub Desktop.
Concurrent clients with fs2-http
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
// 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