Pool
Generalized object pool implementation. Implemented as a thread safe stack. Exclusive locking is needed both for push and pop.
Methods
new
obtain
pop
push
Included Modules
- MonitorMixin
Public Class methods
[ + ]
# File lib/more/facets/pool.rb, line 39 def initialize super @cv = new_cond() end
Public Instance methods
Obtains an object, passes it to a block for processing and restores it to the pool.
[ + ]
# File lib/more/facets/pool.rb, line 65 def obtain result = nil begin obj = pop() result = yield(obj) ensure push(obj) end return result end
Obtain an object from the pool.
[ + ]
# File lib/more/facets/pool.rb, line 55 def pop synchronize do @cv.wait_while { empty? } super end end
Add, restore an object to the pool.
[ + ]
# File lib/more/facets/pool.rb, line 46 def push(obj) synchronize do super @cv.signal() end end