Project

quack_pool

0.0
No commit activity in last 3 years
No release in over 3 years
A simple resource pool that accepts a resource class to build the pool's resources from.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

QuackPool

QuackPool is a ruby gem. It is a simple resource pool that accepts a resource class to build the pool's resources from.

Features

  • thread safe
  • only builds new resources as needed
  • you can specify a max resource limit

Intall

gem install quack_pool

Example

require 'quack_pool'

class Resource
end

# unlimited resources
pool = QuackPool.new(resource_class: Resource)
resource1 = pool.release_resource
resource2 = pool.release_resource
# use resources ...
pool.absorb_resource(resource1)
pool.absorb_resource(resource2)

# limited resources
pool = QuackPool.new(resource_class: Resource, size: 2)
resource1 = pool.release_resource
thread = Thread.new do
  resource2 = pool.release_resource
  # use resource ...
  sleep 2
  pool.absorb_resource(resource1)
end
sleep 1
resource3 = pool.release_resource # will block until a resource is available
# use resources ...
pool.absorb_resource(resource1)
pool.absorb_resource(resource3)
thread.join