I started looking at the source code, and indeed the Async block simply wraps the Result into a Promise.
I started looking for how the promise is handled, and all I could find was the following snippet in the PlayDefaultUpstreamHandler:
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
...
val response = new Response {
def handle(result: Result) {
result match {
case AsyncResult(p) => p.extend1 {
case Redeemed(v) => handle(v)
case Thrown(e) => {
server.applicationProvider.get match {
case Right(app) => handle(app.handleError(requestHeader, e))
case Left(_) => handle(Results.InternalServerError)
}
}
}
...
So if the result is ready, its handled. But what I can't find is what happens if the result is not yet ready. I presume its stuck back on a queue and checked later. But what happens if there are no other requests to handle... does the Play server run in a continuous while loop checking the result and heating the CPU? Or does it poll every X milliseconds? Or is it truly a callback, which WS.url(...).get calls, when the result comes in?
Cheers for any help!
Ant