Closed gkrcode closed 12 years ago
@rewinfrey may have a better idea, but here's what I suggest.
Let's assume that your process_new_emails
function is going to return a Deferrable (because you're probably going to want to do something async in there — if not, just make the function return DG::success
).
Then it's just a case of saying "after you've processed the new emails, idle again"; which is (in Deferrable speak): .callback{ idle_loop(client) }
.
That gives you a function (untested) that works like this:
def idle_loop(client)
idler = client.idle
idler.listen do |response|
if (response.name == "EXISTS" rescue nil)
puts "Ooh, new emails!"
idler.stop
idler.callback do
process_new_emails.callback{ idle_loop(client) }
end
end
end.errback do |e|
puts "Idler recieved an error: #{e}"
end
end
I think I should add an example like this to the README. Will wait for feedback from you and @rewinfrey first.
Thanks, It works :)
Hi,
idler = client.idle
idler.listen do |response| if (response.name == "EXISTS" rescue nil) puts "Ooh, new emails!" idler.stop idler.callback do
... process new emails
end end.errback do |e| puts "Idler recieved an error: #{e}" end
How to re-IDLE after processing idler.callback in a right way ?
Thanks