Browse files

- Removed dependency on SystemTimer gem for rubies > 1.8.x

  • Loading branch information...
1 parent 6e06345 commit da06f80cf147232147081355f1a49af110889b78 Amol Hatwár committed May 24, 2010
Showing with 27 additions and 11 deletions.
  1. +27 −11 lib/fetcher/imap.rb
View
38 lib/fetcher/imap.rb
@@ -1,4 +1,4 @@
-require 'system_timer'
+(RUBY_VERSION < '1.9.0') ? require('system_timer') : require('timeout')
require File.dirname(__FILE__) + '/../vendor/plain_imap'
module Fetcher
@@ -27,17 +27,33 @@ def initialize(options={})
# Open connection and login to server
def establish_connection
- # Work around a freezing bug in Ruby's IMAP implementation using the SystemTimer library.
- # It will have a SIGALRM sent to the process if this block doesn't exit in 15 seconds.
- # Ruby's timeout's are unreliable if a system call is invoked.
- SystemTimer.timeout_after(15.seconds) do
- @connection = Net::IMAP.new(@server, @port, @ssl)
- if @use_login
- @connection.login(@username, @password)
- else
- @connection.authenticate(@authentication, @username, @password)
+ meth18 = <<-eos
+ # Work around a freezing bug in Ruby's IMAP implementation using the SystemTimer library.
+ # It will have a SIGALRM sent to the process if this block doesn't exit in 15 seconds.
+ # Ruby 1.8 timeouts are unreliable if a system call is invoked.
+ SystemTimer.timeout_after(15.seconds) do
+ @connection = Net::IMAP.new(@server, @port, @ssl)
+ if @use_login
+ @connection.login(@username, @password)
+ else
+ @connection.authenticate(@authentication, @username, @password)
+ end
end
- end
+ eos
+
+ meth19 = <<-eos
+ # Use the normal native threading goodness that Ruby 1.9 onwards provide for timeouts.
+ Timeout::timeout(15) do
+ @connection = Net::IMAP.new(@server, @port, @ssl)
+ if @use_login
+ @connection.login(@username, @password)
+ else
+ @connection.authenticate(@authentication, @username, @password)
+ end
+ end
+ eos
+
+ (RUBY_VERSION < '1.9.0') ? eval(meth18) : eval(meth19)
end
# Retrieve messages from server

0 comments on commit da06f80

Please sign in to comment.