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
Source
# File lib/typhoeus/pool.rb, line 47 def self.clear @mutex.synchronize { easies.clear } end
Clear the pool
Source
# 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
Return an easy from the pool.
@example Return easy.
Typhoeus::Pool.get
@return [ Ethon::Easy ] The easy.
Source
# 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
Releases easy into the pool. The easy handle is reset before it gets back in.
@example Release easy.
Typhoeus::Pool.release(easy)
Source
# File lib/typhoeus/pool.rb, line 57 def self.with_easy(&block) easy = get yield easy ensure release(easy) if easy end
Use yielded easy, will be released automatically afterwards.
@example Use easy.
Typhoeus::Pool.with_easy do |easy| # use easy end