module Typhoeus::Pool
The easy pool stores already initialized easy handles for future use. This is useful because creating them is expensive.
@api private
Public Class Methods
clear()
click to toggle source
Clear the pool
# File lib/typhoeus/pool.rb, line 34 def self.clear @mutex.synchronize { easies.clear } end
get()
click to toggle source
Return an easy from the pool.
@example Return easy.
Typhoeus::Pool.get
@return [ Ethon::Easy ] The easy.
# File lib/typhoeus/pool.rb, line 29 def self.get @mutex.synchronize { easies.pop } || Ethon::Easy.new end
release(easy)
click to toggle source
Releases easy into the pool. The easy handle is reset before it gets back in.
@example Release easy.
Typhoeus::Pool.release(easy)
# File lib/typhoeus/pool.rb, line 18 def self.release(easy) easy.reset @mutex.synchronize { easies << easy } end
with_easy() { |easy| ... }
click to toggle source
Use yielded easy, will be released automatically afterwards.
@example Use easy.
Typhoeus::Pool.with_easy do |easy| # use easy end
# File lib/typhoeus/pool.rb, line 44 def self.with_easy(&block) easy = get yield easy ensure release(easy) if easy end
Private Class Methods
easies()
click to toggle source
# File lib/typhoeus/pool.rb, line 53 def self.easies @easies ||= [] end