scala - 如何在不阻塞的情况下运行一系列期货并等待完成?
问题描述
我在 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(())
}
})
推荐阅读
- cordova - LocalFileSystem.PERSISTENT 和 LocalFileSystem.TEMPORARY 是否仍在 cordova-plugin-file 中运行?
- python - Python 没有检测到子字符串,即使它存在(字符串来自 argparse 的输出)
- shell - 如何从终端的 python 输出中输出数据?
- wso2 - APIM 2.6.0 微网关 - 类转换异常
- amazon-web-services - 根据参数值创建 AWS 资源
- c++ - 获取属性连接方向盘
- postgresql - 在计算列 postgresql 中使用 case 表达式
- php - Mysql/PHP Json 嵌套数组
- html - 引导第一个容器覆盖第二个容器
- c - C、在结构中使用动态数组时出现分段错误