Play: should you always use Action.async?

I am a little confused about how to play! works in its controller layer. Some documents indicate that Play! always asynchronous and not blocked. Therefore, I am confused by Action vs Action.async. Block action? If so, and the docs say you should always remain asynchronous and non-blocking, should Action.async always be used in all your controllers? Why don't you choose not too? I am sure that there is something that I do not understand here, and any of your knowledge would be greatly appreciated in understanding this.

+6
source share
2 answers

Playback is completely asynchronous and non-blocking.

Most actions usually require inline execution, so Play conveniently reflects this. However, if you have an asynchronous operation in your action (for example, a WS call), you use Action.async to convey the future result.

+5
source

Action blocked, and it takes a function from Request=>Result , so you can do any blocking things in it. Action.async is non-blocking and requires a function from Request=>Future[Result] , but here it is important to understand that only non-blocking material in it matters, because if you block some where next, it will be pointless. The WS call mentioned by @Christopher Hunt is a good example because it gives you a future [Answer] that you can easily convert to Future[Result] what Action.async expects as a return type. But you can use the scala.Future API for any material that can be asynchronous and non-blocking.

+1
source

All Articles