From 68fc350abe3b62f0d029877da8613791ac78ff8d Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 22 Oct 2015 09:32:19 +0000 Subject: * lib/net/imap (idle): add a new argument timeout for keep-alive. [ruby-core:63693] [Bug #10031] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/imap.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/net') diff --git a/lib/net/imap.rb b/lib/net/imap.rb index cc7935ec43..5d642ecac4 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -935,7 +935,17 @@ module Net # messages. Yields responses from the server during the IDLE. # # Use #idle_done() to leave IDLE. - def idle(&response_handler) + # + # If +timeout+ is given, this method returns after +timeout+ seconds passed. + # +timeout+ can be used for keep-alive. For example, the following code + # checks the connection for each 60 seconds. + # + # loop do + # imap.idle(60) do |res| + # ... + # end + # end + def idle(timeout = nil, &response_handler) raise LocalJumpError, "no block given" unless response_handler response = nil @@ -947,7 +957,7 @@ module Net begin add_response_handler(response_handler) @idle_done_cond = new_cond - @idle_done_cond.wait + @idle_done_cond.wait(timeout) @idle_done_cond = nil if @receiver_thread_terminating raise Net::IMAP::Error, "connection closed" -- cgit v1.2.3