简体   繁体   中英

Asynchronous results in Play 2.0 Framework (scala)

reading the documentation Play claims:

http://www.playframework.org/documentation/2.0/ScalaAsync

"Because of the way Play 2.0 works, the action code must be as fast as possible (ie. non blocking)."

It then goes on to show how to write an asynchronous result. Could somebody expand on why "the action code must be as fast as possible"? How does changing to an asynchronous result effect the way the request is handled on a lower level? What are the benefits, aside from abstraction?

Actually using ASync for calls that might be long or async by essence (call to other remote api like twitter, db, ...) only the client will wait, and not the server (the way Play 2.0 works)

This won't affect how the request it self will be handled, however the whole action will be executed as the result will be promised for further results, using akka actors.

This last point is the key, akka will reuse as much as possible available threads rather keeping them sleeping.

Talking about how I'm using ASync is while using Neo4J REST API to deal with persistent objects, because such usage of database is dependent on the network, bandwidth, query performance, ... it can be cumbersome to have HA solutions, by having most of request waiting. Which in cloud env. will lead you to add processes/instances and finally cost you much ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM