Skip to content

Commit

Permalink
use thread_safe gem instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg committed Oct 27, 2013
1 parent f953a11 commit eb87e26
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/typhoeus.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'digest/sha2'
require 'ethon'
require 'thread_safe'

require 'typhoeus/config'
require 'typhoeus/easy_factory'
Expand Down
12 changes: 4 additions & 8 deletions lib/typhoeus/pool.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'thread'

module Typhoeus

# The easy pool stores already initialized
Expand All @@ -10,16 +8,14 @@ module Typhoeus
module Pool
extend self

@mutex = Mutex.new

# Releases easy into the pool. The easy handle is
# reset before it gets back in.
#
# @example Release easy.
# hydra.release_easy(easy)
def release(easy)
easy.reset
@mutex.synchronize { easies << easy }
easies << easy
end

# Return an easy from the pool.
Expand All @@ -29,11 +25,11 @@ def release(easy)
#
# @return [ Ethon::Easy ] The easy.
def get
@mutex.synchronize { easies.pop } || Ethon::Easy.new
easies.pop || Ethon::Easy.new
end

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

def with_easy(&block)
Expand All @@ -52,7 +48,7 @@ def with_easy(&block)
#
# @return [ Array<Ethon::Easy> ] The easy pool.
def easies
@easies ||= []
@easies ||= ThreadSafe::Array.new
end
end
end
1 change: 1 addition & 0 deletions typhoeus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.license = 'MIT'

s.add_dependency('ethon', ["~> 0.6.1"])
s.add_dependency('thread_safe', ["~> 0.1.3"])

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")
Expand Down

3 comments on commit eb87e26

@myronmarston
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is causing problems for me updating VCR to utilize the new encoded_body API you added for me. VCR still supports 1.8.7 (I plan to drop support in VCR 3.0 but SemVer dictates that I can't drop support before then). thread_safe 0.1.3 doesn't support MRI 1.8.7 properly, sadly (I get uninitialized constant ThreadSafe::Array errors). It looks like this got fixed in headius/thread_safe#7 but there hasn't been a gem release with that fix yet.

@headius -- any chance you could release a new thread_safe gem so we have a version that works on 1.8.7? Or, if that's not going to happen soon, @i0rek, could you cut a gem release w/o this but with the encoded_body API?

@hanshasselberg
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@myronmarston I've reverted this commit.

@myronmarston
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.