Last active
November 16, 2018 19:43
-
-
Save clone1018/0295f04daaf7aed54cefe4b111a4e942 to your computer and use it in GitHub Desktop.
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
private def processBatch(results: Future[Seq[String]], batch: Seq[String]): Future[Seq[String]] = { | |
// when the results for the previous batches have been completed, start a new batch | |
results.flatMap { responses => | |
// create the web requests for this batch | |
val batchFutures: Seq[Future[String]] = batch.map(ws.url(_).get().map(_.body)) | |
// sequence the futures for this batch into a singe future | |
val batchFuture: Future[Seq[String]] = Future.sequence(batchFutures) | |
// when this batch is complete, append the responses to the existing responses | |
batchFuture.map { batchResponses => | |
Logger.info("Finished a batch") | |
responses ++ batchResponses | |
} | |
} | |
} |
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
private def processBatch(results: Future[Seq[String]], batch: Seq[String]): Future[Seq[String]] = { | |
// when the results for the previous batches have been completed, start a new batch | |
for { | |
responses <- results | |
// sequence the futures for this batch into a singe future | |
batchFuture = Future.sequence(batch.map(ws.url(_).get().map(_.body))) | |
batchResponses <- batchFuture | |
} yield { | |
// when this batch is complete, append the responses to the existing responses | |
Logger.info("Finished a batch") | |
responses ++ batchResponses | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment