【发布时间】:2019-03-18 06:57:20
【问题描述】:
我试图找到一种更优雅的方法来执行 2 次返回 Future[HttpReponse] 的函数,然后使用 2-end 调用的响应。
for {
// function post returns a Future[HttpResponse]
response <- post(uri, payload) // 1st
response <- post(uri, payload) // 2end
} yield {
// do something with the 2end response
}
这不起作用:
for {
2 times response <- post(uri, payload)
} yield {
// response becomes of type Any instead of HttpResponse
}
【问题讨论】:
-
这两个调用应该同时执行还是顺序执行?
-
依次:-)
-
更新了我的答案以按顺序工作。
标签: scala http asynchronous