Created
September 16, 2010 20:08
-
-
Save mbbx6spp/583075 to your computer and use it in GitHub Desktop.
Pre-fix to work around timeout + Thread#join issue in Ruby 1.8 when using Twitter4R.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in your application code | |
require 'twitter' | |
module MyAppNamespace::Twitter4RTimeoutMixin | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
base.class_eval do | |
# assumes you already depend on ActiveSupport, | |
# but you can mimick with alias_method and more cruft code | |
alias_method_chain :rest_consumer, :timeout | |
alias_method_chain :search_consumer, :timeout | |
end | |
module InstanceMethods | |
def rest_consumer_with_timeout | |
rest_consumer_without_timeout | |
config = self.class.config | |
connection = @rest_consumer.http | |
connection.read_timeout = config.timeout | |
end | |
def search_consumer_with_timeout | |
rest_consumer_without_timeout | |
config = self.class.config | |
connection = @search_consumer.http | |
connection.read_timeout = config.timeout | |
end | |
end | |
end | |
end | |
class Twitter::Client | |
include(MyAppNamespace::Twitter4RTimeoutMixin) | |
end | |
Twitter::Client.configure do |conf| | |
# you other settings here | |
config.timeout = 180 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment