Play and Scala, type match and succesful compile, but I think it's a mismatch -


i implementing playframework custom actions when came question, let me explain little bit:

this code custom action:

object authenticatedaction extends actionbuilder[authenticatedrequest] controller {   def invokeblock[a](request: request[a], block: (authenticatedrequest[a]) => future[result]) = {     request.session.get("username").fold      {       future.successful(forbidden(views.html.forbidden()(request)))     } {       username => block(new authenticatedrequest(username, request))     }   } } 

and code controller action:

def index = authenticatedaction { implicit request =>   ok(views.html.index("your new application ready.")) } 

the thing authenticatedaction needs function returns future[result].

  • in "forbidden" part of invokeblock[a]... wrap result in future
  • but in "authenticated" part, block function not return future[result] , instead returns result (see def index).

the code above compiles , see desired page, don't understand why works. also, if wrap result of block function in future, intelli idea inspector tells me "type mismatch" specifying wants result instead of future[result].

i'm sure i'm missing something, don't know is. can give light mind?

if want return future must this:

def index = authenticatedaction.async { implicit request =>   future.successful(ok) } 

if in api (link below), there apply method takes in "=> result" .async method takes in "=> future[result]".

https://www.playframework.com/documentation/2.4.x/api/scala/index.html#play.api.mvc.actionbuilder


Comments