11.5 Servlet 3.0 Async - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.8
11.5 Servlet 3.0 Async
In addition to the higher level async features discussed earlier in the section, you can access the raw Servlet 3.0 asynchronous API from a Grails application.Servlet 3.0 Asynchronous Rendering
You can render content (templates, binary data etc.) in an asynchronous manner by calling thestartAsync
method which returns an instance of the Servlet 3.0 AsyncContext
. Once you have a reference to the AsyncContext
you can use Grails' regular render method to render content:def index() { def ctx = startAsync() ctx.start { new Book(title:"The Stand").save() render template:"books", model:[books:Book.list()] ctx.complete() } }
complete()
method to terminate the connection.Resuming an Async Request
You resume processing of an async request (for example to delegate to view rendering) by using thedispatch
method of the AsyncContext
class:def index() {
def ctx = startAsync()
ctx.start {
// do working
…
// render view
ctx.dispatch()
}
}