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


45
46
47
# File 'lib/typhoeus/pool.rb', line 45

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

Since:

  • 0.5.0


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

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
# File 'lib/typhoeus/pool.rb', line 19

def self.release(easy)
  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


55
56
57
58
59
60
# File 'lib/typhoeus/pool.rb', line 55

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