One Action returns Future[Result] while other returns Accumultor[]

74 views Asked by At

I have created the following two Actions

def action1: Action[Either[MaxSizeExceeded, AnyContent]] = silhouette.SecuredAction.async(parse.maxLength(maxAllowedBodySize, parse.anyContent)(materializer)) { ...}


def action2:Action[AnyContent] = silhouette.UserAwareAction.async { ...}

While unit testing them, I found that result of action1's return is Future[Result] while that of action2 is Accumulator[ByteString, Result]

val response:Accumulator[ByteString,Result] = testEnv.controller.action1(request)

val response:Future[Result] = userTestEnv.controller.action2(request)

I can't quite figure out why there is a difference? Why are return type different?

1

There are 1 answers

0
Manu Chadha On

I believe the reason is that for Action of type [Either[MaxSizeExceeded, AnyContent]], the Action returns Accumulator - https://www.playframework.com/documentation/2.6.x/ScalaEssentialAction

In general, it seems that if Play knows that the body can be fit in memory then it returns Future[Result] otherwise it returns Accumulator.