Reputation: 1
I have a requirement in Scala to run a series of http calls that have to be completed in sequence and without blocking. How can I achieve that?
Upvotes: 0
Views: 203
Reputation: 582
You want to have a look at the foldLeft
function or your TraversableLike
containing the series of calls or their specs:
val seriesOfOrderedCalls = Seq(..)
val eventuallyCompleted = seriesOfOrderedCalls
.foldLeft(Future.successful(()))((prev, call) => {
prev.flatMap { _ =>
// do your call here
// then return the future of the call
Future.successful(())
}
})
Upvotes: 1