我在Scala中有一个要求,要求运行一系列http调用,这些调用必须按顺序完成,并且没有阻塞。我怎样才能做到这一点?
您需要查看包含一系列调用或其规范的foldLeft
函数或TraversableLike
:
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(())
}
})