Sha256: cd643d8dd9b4c2b0f9d54c512e1b9443bde54d9205a8e15ee972a1c40e271a76

Contents?: true

Size: 1.55 KB

Versions: 6514

Compression:

Stored size: 1.55 KB

Contents

require 'thread'

module Typhoeus

  # The easy pool stores already initialized
  # easy handles for future use. This is useful
  # because creating them is expensive.
  #
  # @api private
  module Pool
    @mutex = Mutex.new
    @pid = Process.pid

    # Releases easy into the pool. The easy handle is
    # reset before it gets back in.
    #
    # @example Release easy.
    #   Typhoeus::Pool.release(easy)
    def self.release(easy)
      easy.cookielist = "flush" # dump all known cookies to 'cookiejar'
      easy.cookielist = "all" # remove all cookies from memory for this handle
      easy.reset
      @mutex.synchronize { easies << easy }
    end

    # Return an easy from the pool.
    #
    # @example Return easy.
    #   Typhoeus::Pool.get
    #
    # @return [ Ethon::Easy ] The easy.
    def self.get
      @mutex.synchronize do
        if @pid == Process.pid
          easies.pop
        else
          # Process has forked. Clear all easies to avoid sockets being
          # shared between processes.
          @pid = Process.pid
          easies.clear
          nil
        end
      end || Ethon::Easy.new
    end

    # Clear the pool
    def self.clear
      @mutex.synchronize { easies.clear }
    end

    # Use yielded easy, will be released automatically afterwards.
    #
    # @example Use easy.
    #   Typhoeus::Pool.with_easy do |easy|
    #     # use easy
    #   end
    def self.with_easy(&block)
      easy = get
      yield easy
    ensure
      release(easy) if easy
    end

    private

    def self.easies
      @easies ||= []
    end
  end
end

Version data entries

6,514 entries across 6,511 versions & 26 rubygems

Version Path
cybrid_api_organization_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_bank_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_id_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
cybrid_api_organization_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb
ory-client-1.15.10 vendor/bundle/ruby/3.1.0/gems/typhoeus-1.4.1/lib/typhoeus/pool.rb