2
在下面的一段代碼中,我試圖返回一個異步結果,在這種情況下是一個Akka.future。當我試圖映射的方法的響應結果,我得到的是說返回Akka.Future - 播放框架
[error] Test.scala:180: type mismatch;
[error] found : scala.concurrent.Future[play.api.mvc.SimpleResult[String]]
[error] required: play.api.mvc.Result
[error] jsonResponse.map((s: String) => Ok(s))
這裏編譯錯誤是我的嘗試:
def testAkka(jsonList: List[String]) = Action {
Async {
val ftrList: List[Future[String]] = jsonList.map((s: String) => Akka.future {returnSomeVal(s)})
val futureList: Future[List[String]] = Future.sequence(ftrList)
val jsonResponse: Future[String] = futureList.map((f: List[String]) => f.mkString(","))
Akka.future {
jsonResponse.map((s: String) => Ok(s)) // Compiler complains here
//Ok(jsonResponse)
}
}
}
你在用什麼版本的Play? – Damiya