Are there any advantages to using non-asynchronous actions in Play Framework 2.2?

The Play 2.2 documentation says that:

Due to how Play works, the action code should be as fast as possible (i.e. not block). So what should we return as a result if we cannot create it yet? The answer is the future result!

The future [Result] will ultimately be redeemed with a value of type Result. By providing the future [Result] instead of the usual result, we can quickly generate the result without blocking. Then Play will fulfill this result as soon as the promise is paid.

The web client will be blocked awaiting a response, but nothing will be blocked on the server, and server resources can be used to serve other clients.

Actions that return the future are created Action.async, unlike Action.applyfor ordinary, non-asynchronous actions.

Is there any benefit from non-asynchronous actions? It seems to me that the best way to guarantee that none of my actions will be blocked is to declare all of them with help Action.async.

In fact, according to the Play Framework 2.3 documentation , it looks like in Play 2.3 all actions are asynchronous:

. Action.apply, Action.async Action, . Action, , ( ). .async - API, , .

+4
1

, Action.async, , . , API .

Play 2.2, , , Play 2.3 . Action.apply Action.async . Action.async , Future[Result], Action.apply , Result. Action.apply , block: => Result Future[Result] Future.successful(block). ( , Future.successful, .)

, API. , JDBC vs ScalikeJDBC-async, API . , json.

JDBC ( ):

def read(id: Long): User

:

def read(id: Long) = Action {
    Ok(Json.toJson(User.read(id))
}

, Action.apply :

def read(id: Long) = Action.async {
    Future.successful(Ok(Json.toJson(User.read(id)))
}

User.read - JDBC, , .

, , :

def read(id: Long): Future[User]

:

def read(id: Long) = Action.async {
    User.read(id).map(user => Ok(Json.toJson(user)))
}

API, Future s. API. API (, JDBC), . Play : https://groups.google.com/forum/#!topic/play-framework/WWQ0HeLDOjg

+11

Source: https://habr.com/ru/post/1542938/