playframework - Scala Play 2.5 Turning an Action into A Result -
in play scala project, i'm returning object inside of controller type:
play.api.mvc.action[play.api.libs.json.jsvalue
however, play complaining expecting play.api.mvc.result
. according docs, action function handles request , generates result.
def mycontroller = myspecialfunction.asyc(prase.tolerantjson) { implicit request => { { ... stuff ... } yield { myfunction() } } }
in case, myfunction has return type of play.api.mvc.action[play.api.libs.json.jsvalue
.
i want return result, , i'm not sure how correctly call function
your action.async
block expects function request
future[result]
.
now, myfunction()
inside yield
block returning jsvalue
return type. if comprehension on futures, output of for-comprehension becomes future[jsvalue]
. play expects future[result]
. transform result future[result]
. final output type should future[result]
.
for example
action.async { req => val resultfuture = { _ <- getusersfuture _ <- dosomethingfuture } yield (myfunction) resultfuture.map { json => ok(json) } }
Comments
Post a Comment