I am trying to complete a Promise[String] for my Action. So far I've read the Play's documentation on asynchronous programming at http://www.playframework.com/documentation/2.0/ScalaAsync but there's something I am not getting - or the docs are wrong :)
Here's an outline of my code. My intention is to return a Promise[String] and complete that in my Action. The content of the Promise may come from different places, so I would like to be able to return a Promise[String] to have the Action handler simple.
def getJson = Action { request =>
val promiseOfJson = models.item.getJson
Async {
promiseOfJson.map(json => Ok(json))
}
}
def models.item.getJson: Promise[String] = {
val resultPromise = promise[String]
future {
...
resultPromise success "Foo"
}
resultPromise
}
Looking at Play's documentation and at "AsyncResult" I think I am doing the same thing, no?
Problem is that I get a compilation error inside my Async {} block:
value map is not a member of scala.concurrent.Promise[String]