connection_pool 0.9.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changes.md CHANGED
@@ -1,3 +1,11 @@
1
+ 1.0.0
2
+ -----
3
+
4
+ - `#with_connection` is now gone in favor of `#with`.
5
+
6
+ - We no longer pollute the top level namespace with our internal
7
+ `TimedStack` class.
8
+
1
9
  0.9.3
2
10
  --------
3
11
 
@@ -1,5 +1,4 @@
1
1
  require_relative 'connection_pool/version'
2
- require_relative 'timed_queue'
3
2
 
4
3
  # Generic connection pool class for e.g. sharing a limited number of network connections
5
4
  # among many threads. Note: Connections are eager created.
@@ -39,7 +38,7 @@ class ConnectionPool
39
38
  @size = options.fetch(:size)
40
39
  @timeout = options.fetch(:timeout)
41
40
 
42
- @available = ::TimedQueue.new(@size, &block)
41
+ @available = TimedStack.new(@size, &block)
43
42
  @key = :"current-#{@available.object_id}"
44
43
  end
45
44
 
@@ -52,16 +51,11 @@ class ConnectionPool
52
51
  end
53
52
  end
54
53
 
55
- def with_connection(&block)
56
- warn("ConnectionPool#with_connection is deprecated and will be removed in version 1.0. Upgrade your code to use ConnectionPool#with instead. (in #{caller[0]})")
57
- with(&block)
58
- end
59
-
60
54
  def checkout
61
55
  stack = ::Thread.current[@key] ||= []
62
56
 
63
57
  if stack.empty?
64
- conn = @available.timed_pop(@timeout)
58
+ conn = @available.pop(@timeout)
65
59
  else
66
60
  conn = stack.last
67
61
  end
@@ -92,11 +86,6 @@ class ConnectionPool
92
86
  @pool.checkin
93
87
  end
94
88
 
95
- def with_connection(&block)
96
- warn("ConnectionPool::Wrapper#with_connection is deprecated and will be removed in version 1.0. Upgrade your code to use ConnectionPool::Wrapper#with instead. (in #{caller[0]})")
97
- with(&block)
98
- end
99
-
100
89
  def respond_to?(id, *args)
101
90
  METHODS.include?(id) || @pool.with { |c| c.respond_to?(id, *args) }
102
91
  end
@@ -108,3 +97,5 @@ class ConnectionPool
108
97
  end
109
98
  end
110
99
  end
100
+
101
+ require_relative 'connection_pool/timed_stack'
@@ -1,7 +1,7 @@
1
1
  require 'thread'
2
2
  require 'timeout'
3
3
 
4
- class TimedQueue
4
+ class ConnectionPool::TimedStack
5
5
  def initialize(size = 0)
6
6
  @que = Array.new(size) { yield }
7
7
  @mutex = Mutex.new
@@ -16,7 +16,7 @@ class TimedQueue
16
16
  end
17
17
  alias_method :<<, :push
18
18
 
19
- def timed_pop(timeout=0.5)
19
+ def pop(timeout=0.5)
20
20
  deadline = Time.now + timeout
21
21
  @mutex.synchronize do
22
22
  loop do
@@ -1,3 +1,3 @@
1
1
  class ConnectionPool
2
- VERSION = "0.9.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connection_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -26,8 +26,8 @@ files:
26
26
  - Rakefile
27
27
  - connection_pool.gemspec
28
28
  - lib/connection_pool.rb
29
+ - lib/connection_pool/timed_stack.rb
29
30
  - lib/connection_pool/version.rb
30
- - lib/timed_queue.rb
31
31
  - test/helper.rb
32
32
  - test/test_connection_pool.rb
33
33
  homepage: https://github.com/mperham/connection_pool