diff options
Diffstat (limited to 'lib')
-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" |