basho/innertube
A thread-safe re-entrant resource pool for Ruby, extracted from the Riak Ruby Client.
{ "createdAt": "2012-06-01T13:22:11Z", "defaultBranch": "master", "description": "A thread-safe re-entrant resource pool for Ruby, extracted from the Riak Ruby Client.", "fullName": "basho/innertube", "homepage": "http://rubygems.org/gems/innertube", "language": "Ruby", "name": "innertube", "pushedAt": "2016-06-03T21:38:33Z", "stargazersCount": 58, "topics": [], "updatedAt": "2025-06-11T06:04:08Z", "url": "https://github.com/basho/innertube"}Innertube
Section titled “Innertube”Innertube is a thread-safe, re-entrant resource pool, extracted from the Riak Ruby Client, where it was used to pool connections to Riak. It is free to use and modify, licensed under the Apache 2.0 License.
Example
Section titled “Example”# -------------------------------------------------------# Basics# -------------------------------------------------------
# Create a pool with open/close callablespool = Innertube::Pool.new(proc { Connection.new }, proc {|c| c.disconnect })
# Optionally, fill the pool with existing resourcespool.fill([conn1, conn2, conn3])
# Grab a connection from the pool, returns the same value# as the blockpool.take {|conn| conn.ping } # => true
# Raise the BadResource exception if the resource is no# longer goodpool.take do |conn| raise Innertube::Pool::BadResource unless conn.connected? conn.pingend
# Innertube helps your code be re-entrant! Take more resources# while you have one checked out.pool.take do |conn| conn.stream_tweets do |tweet| pool.take {|conn2| conn2.increment :tweets } endend
# -------------------------------------------------------# Iterations: These are slow because they have guarantees# about visiting all current elements of the pool.# -------------------------------------------------------
# Do something with every connection in the poolpool.each {|conn| puts conn.get_stats }
# Expunge some expired connections from the poolpool.delete_if {|conn| conn.idle_time > 5 }Credits
Section titled “Credits”The pool was originally implemented by Kyle Kingsbury and extracted by Sean Cribbs, when bugged about it by Pat Allan at EuRuKo 2012.