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).
Use this in DispatchPF for processing REST requests asynchronously.
Use this in DispatchPF for processing REST requests asynchronously. Note that this must be called in a stateful context, therefore the S state must be a valid one.
- the user function that does the actual computation. This function takes one parameter which is the functino that must be invoked for returning the actual response to the client. Note that f function is invoked asynchronously in the context of a different thread.
(Since version 2.4) Use RestContinuation.async. It provides much better resource management
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.