summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 09:32:19 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 09:32:19 +0000
commit68fc350abe3b62f0d029877da8613791ac78ff8d (patch)
treef9d5c23baa2a09dc092edf96db6b95d15e0b2d7a /lib
parent30b839a013a347d5d474217714e313f18dbef08c (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/net/imap.rb14
1 files changed, 12 insertions, 2 deletions
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"