Module: Typhoeus::Pool Private

Defined in:
lib/typhoeus/pool.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

The easy pool stores already initialized easy handles for future use. This is useful because creating them is expensive.

Since:

  • 0.5.0

Class Method Summary collapse

Class Method Details

.clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clear the pool

Since:

  • 0.5.0



47
48
49
# File 'lib/typhoeus/pool.rb', line 47

def self.clear
  @mutex.synchronize { easies.clear }
end

.getEthon::Easy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return an easy from the pool.

Examples:

Return easy.

Typhoeus::Pool.get

Returns:

  • (Ethon::Easy)

    The easy.

Since:

  • 0.5.0



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/typhoeus/pool.rb', line 32

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

.release(easy) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Releases easy into the pool. The easy handle is reset before it gets back in.

Examples:

Release easy.

Typhoeus::Pool.release(easy)

Since:

  • 0.5.0



19
20
21
22
23
24
# File 'lib/typhoeus/pool.rb', line 19

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

.with_easy(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Use yielded easy, will be released automatically afterwards.

Examples:

Use easy.

Typhoeus::Pool.with_easy do |easy|
  # use easy
end

Since:

  • 0.5.0



57
58
59
60
61
62
# File 'lib/typhoeus/pool.rb', line 57

def self.with_easy(&block)
  easy = get
  yield easy
ensure
  release(easy) if easy
end