Skip to content

Instantly share code, notes, and snippets.

@robertberry-zz
Created March 25, 2014 23:14
Show Gist options
  • Save robertberry-zz/9773517 to your computer and use it in GitHub Desktop.
Save robertberry-zz/9773517 to your computer and use it in GitHub Desktop.
import scala.concurrent.Future
object Futures {
def batchedTraverse[A, B](as: List[A], batchSize: Int, timeout: Int)(f: A => Future[B]) =
as.grouped(batchSize).foldLeft(Future.successful(List.empty[B])) {
case (accumulatorFuture, batch) => accumulatorFuture flatMap { accumulator =>
Future.traverse(batch)(f) map { accumulator ++ _ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment