Reputation: 15405
In the following piece of code, I'm trying to return an Async result which is an Akka.future in this case. When I tried to map the result for the method's response, I get a compile error that says
[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))
Here is what I tried:
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)
}
}
}
Upvotes: 2
Views: 92