module Typhoeus::Pool

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

@api private

Public Instance Methods

clear() click to toggle source
# File lib/typhoeus/pool.rb, line 35
def clear
  @mutex.synchronize { easies.clear }
end
get() click to toggle source

Return an easy from pool.

@example Return easy.

hydra.get_easy

@return [ Ethon::Easy ] The easy.

# File lib/typhoeus/pool.rb, line 31
def get
  @mutex.synchronize { easies.pop } || Ethon::Easy.new
end
release(easy) click to toggle source

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

@example Release easy.

hydra.release_easy(easy)
# File lib/typhoeus/pool.rb, line 20
def release(easy)
  easy.reset
  @mutex.synchronize { easies << easy }
end
with_easy() { |easy| ... } click to toggle source
# File lib/typhoeus/pool.rb, line 39
def with_easy(&block)
  easy = get
  yield easy
ensure
  release(easy) if easy
end

Private Instance Methods

easies() click to toggle source

Return the easy pool.

@example Return easy pool.

hydra.easy_pool

@return [ Array<Ethon::Easy> ] The easy pool.

# File lib/typhoeus/pool.rb, line 54
def easies
  @easies ||= []
end