1
votes

Are all actions in Play Framework 2 async? Or do I have to use Promises deliberately to achieve this?

To clarify, is the IO (NIO) performed on a different thread than the actual action logic?

2
What I'm about so say is a very simplified view, so take it as such (but I hope you'll get the gist): Nope, your actions are not async. Well, not automatically. The thing about play bragging to be async and such is that you can just return AsyncResults, which [you can create easily](playframework.com/documentation/2.1.1/ScalaAsync]. Same thing with everything else. it is not async, it just gives you the tools to easily use async stuff. - Carsten

2 Answers

2
votes

It depends on what you mean by asynchronous.

All Play actions are non-blocking in the sense that the IO thread that accepts the HTTP request is not the same as the one that runs the action, and never blocks waiting the action to complete. So yes, (HTTP) IO are performed on a different thread than the actual action logic.

Though, the actions themselves can contain computations that may take a while. Thus they may block the thread they are executed in. That's often the case when you perform database operations, because most database drivers are blocking.

2
votes

To add to Stephane's answer,

To clarify, is the IO (NIO) performed on a different thread than the actual action logic

Yes it is