diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-22 09:32:19 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-22 09:32:19 +0000 |
commit | 0b13a5a2c267ccef8b263d5beadbb8953e5fbc08 (patch) | |
tree | f9d5c23baa2a09dc092edf96db6b95d15e0b2d7a /lib/net | |
parent | 873982877cd463b15212ca51e545eb0b37cc1828 (diff) | |
download | ruby-0b13a5a2c267ccef8b263d5beadbb8953e5fbc08.tar.gz |
* 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/net')
-rw-r--r-- | lib/net/imap.rb | 14 |
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" |