Process a request asynchronously.
Process a request asynchronously. If your web container supports
Async calls/Continuations (e.g., Jetty 6, Jetty 7, and Servlet 3.0
containers including Jetty 8 and Glassfish), the thread will not
block until there's a response. The parameter is a function
that takes a function as it's parameter. The function is invoked
when the calculation response is ready to be rendered:
RestContinuation.async {
reply => {
myActor ! DoCalc(123, answer => reply{XmlResponse({answer})})
}
}
class MyActor {
def lowPriority = {
case DoCalc(value, whenDone) => whenDone(value * 10)
}
}
Alternatively, from RestHelper:
serve {
case "api" :: id _ Get _ => RestContinuation.async {
reply => for {i <- longCalc(id)} reply(
The body of the function will be executed on a separate thread. When the answer is ready, apply the reply function... the function body will be executed in the scope of the current request (the current session and the current Req object).
Provides a generic way of sending asynchronous response to HTTP clients. If the underlying web container does not support continuations the asynchronous nature is achieved using locks.