I'm a newby in Scala :( That's said, I'm fighting against Play framework Action.async and Future calls.
I'd like to call 2 Futures in the same Action and wait until they both compute to send their result in my view.
Here is the code :
def showPageWithTags(category: String) = Action.async {
val page = PageDAO.findOne(Json.obj("category" -> category)).map {
case Some(page) => {
page.content = page.content.byteArrayToString
}
}
val futureTags = ArticleDAO.listTags
Ok(views.html.web.pages.show(page, futureTags))
}
with this defined functions :
def findOne(id: String): Future[Option[PageModel]]
def listTags: Future[List[String]]
I get this errors :
[error] found : Some[A]
[error] required: models.PageModel
[error] case Some(page) => {
[error] ^
.../...
[error] found : None.type
[error] required: models.PageModel
[error] case None => {
[error] ^
.../...
[error] found : Option[Nothing]
[error] required: scala.concurrent.Future[play.api.mvc.Result]
[error] optionPage.map {
[error] ^
.../...
[error] found : scala.concurrent.Future[Unit]
[error] required: models.PageModel
[error] Ok(views.html.web.pages.show(optionPage, futureTags))
[error] ^
.../...
[error] found : scala.concurrent.Future[List[String]]
[error] required: List[String]
[error] Ok(views.html.web.pages.show(optionPage, futureTags))
[error] ^
I've tried map, for/yield, foreach to deal with Option and Future but there is always one of this errors which remains.
Yet the one Future call was working good before I add the "Tag" functionality :
def showPage(category: String) = Action.async {
PageDAO.findOne(Json.obj("category" -> category)).map {
case Some(page) => {
page.content = page.content.byteArrayToString
Ok(views.html.web.pages.show(page))
}
case None => {
NotFound
}
}
}
How can I call 2 Futures in the same action and wait until they both compute to pass them to my page view via Ok() ?
Many thanks to any clarifications !