innertube 1.0.2 → 1.1.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/README.md +3 -0
- data/lib/innertube.rb +11 -0
- data/lib/innertube/version.rb +1 -1
- data/spec/innertube_spec.rb +14 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -16,6 +16,9 @@ licensed under the Apache 2.0 License.
|
|
16
16
|
pool = Innertube::Pool.new(proc { Connection.new },
|
17
17
|
proc {|c| c.disconnect })
|
18
18
|
|
19
|
+
# Optionally, fill the pool with existing resources
|
20
|
+
pool.fill([conn1, conn2, conn3])
|
21
|
+
|
19
22
|
# Grab a connection from the pool, returns the same value
|
20
23
|
# as the block
|
21
24
|
pool.take {|conn| conn.ping } # => true
|
data/lib/innertube.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'set'
|
2
3
|
|
3
4
|
# Innertube is a re-entrant thread-safe resource pool that was
|
4
5
|
# extracted from the Riak Ruby Client
|
@@ -61,6 +62,16 @@ module Innertube
|
|
61
62
|
@pool = Set.new
|
62
63
|
end
|
63
64
|
|
65
|
+
# Populate the pool with existing, open resources.
|
66
|
+
# @param [Array] An array of resources.
|
67
|
+
def fill(resources)
|
68
|
+
@lock.synchronize do
|
69
|
+
resources.each do |r|
|
70
|
+
@pool << Element.new(r)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
64
75
|
# On each element of the pool, calls close(element) and removes it.
|
65
76
|
# @private
|
66
77
|
def clear
|
data/lib/innertube/version.rb
CHANGED
data/spec/innertube_spec.rb
CHANGED
@@ -51,6 +51,20 @@ describe Innertube::Pool do
|
|
51
51
|
pool_members.map { |e| e.object.first }.sort.should == [1,2,3,4]
|
52
52
|
end
|
53
53
|
|
54
|
+
it 'should be fillable with existing resources' do
|
55
|
+
pool.fill(["Apple", "Banana", "Kiwi"])
|
56
|
+
pool_members.size.should == 3
|
57
|
+
|
58
|
+
pool.take do |x|
|
59
|
+
x.should eq('Apple')
|
60
|
+
pool.take do |y|
|
61
|
+
y.should eq('Banana')
|
62
|
+
pool.take do |z|
|
63
|
+
z.should eq('Kiwi')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
54
68
|
|
55
69
|
it 'should unlock when exceptions are raised' do
|
56
70
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: innertube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -77,3 +77,4 @@ test_files:
|
|
77
77
|
- spec/support/timeout.rb
|
78
78
|
- spec/support/verbose_formatter.rb
|
79
79
|
- .gitignore
|
80
|
+
has_rdoc:
|