Reputation: 9928
class MyController {
def startTwoMinuteTask = {
response.contentType = 'text/html'
def out = response.outputStream.destination
out.println 'Starting ...'
out.flush()
for (int i=0;i<10;i++) {
out.println " <br> $i"
out.flush()
Thread.sleep(1000)
}
return null
}
}
I'd like this to display 1 through 10 as status updates, alas grails is buffering the the entire thing. How do I make this work? Thanks!
Upvotes: 0
Views: 842
Reputation: 39570
I know this isn't the actual answer to your question, but why aren't you using a background Thread?
Using something like the Quartz plugin will let you spin off the long-running process. You can have the browser poll for changes periodically (or using a feature like Atmosphere for push if you can).
The benefit of this is you aren't locking open a connection. Also, not all browsers will wait that long — sometimes they'll time out. HTTP isn't really intended as a long-running connection, especially if no information is being passed.
Upvotes: 1