Sha256: 673ee901373a3d2d1ef9738bfa6b7b2c127af57b667738e83e286ae548b50d1c

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))

require 'rack/utils'
require 'digest/sha2'
require 'typhoeus/easy'
require 'typhoeus/multi'
require 'typhoeus/native'
require 'typhoeus/filter'
require 'typhoeus/remote_method'
require 'typhoeus/remote'
require 'typhoeus/remote_proxy_object'
require 'typhoeus/response'
require 'typhoeus/request'
require 'typhoeus/hydra'

module Typhoeus
  VERSION = "0.1.24"

  def self.easy_object_pool
    @easy_objects ||= []
  end

  def self.init_easy_object_pool
    20.times do
      easy_object_pool << Typhoeus::Easy.new
    end
  end

  def self.release_easy_object(easy)
    easy.reset
    easy_object_pool << easy
  end

  def self.get_easy_object
    if easy_object_pool.empty?
      Typhoeus::Easy.new
    else
      easy_object_pool.pop
    end
  end

  def self.add_easy_request(easy_object)
    Thread.current[:curl_multi] ||= Typhoeus::Multi.new
    Thread.current[:curl_multi].add(easy_object)
  end

  def self.perform_easy_requests
    multi = Thread.current[:curl_multi]
    start_time = Time.now
    multi.easy_handles.each do |easy|
      easy.start_time = start_time
    end
    multi.perform
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typhoeus-0.1.26 lib/typhoeus.rb
typhoeus-0.1.25 lib/typhoeus.rb
typhoeus-0.1.24 lib/typhoeus.rb