Yes, Robert, exactly.
My understanding of what Dave posted is that he is also trying to achieve that, see for example the part localPoll: while (counter < 10){
if (changed){
//render a response to say something has changed
break localPoll
}else{
Thread.currentThread.sleep(5000)
counter+=1
}
I'm doing similar things but with plain while and return, not localPoll:while and break.
The idea is not to have the client ask for news all the time, cluttering the server with requests. Instead, the client opens an Ajax request, lets it sit there waiting, and the server loops checking for new database items and re-renders the list view to the response if new items are found in my case. The client side Javascript, after receiving the response, updates the DOM element with the list and re-issues the request for updates.
This kind of approach is referred to often as Ajax long polling, or reverse Ajax, a variant of Comet style Ajax.
I used a controller and not a service for that because, with services you would first need to expose them somehow and you have all sorts of limitations if you want to access scopes like session from a service which I couldn't solve.
Robert Fischer wrote:
Why is your controller in a loop? Are you trying for some kind of server-push implementation?
~~ Robert.