Pool
Generalized object pool implementation. Implemented as a thread safe stack. Exclusive locking is needed both for push and pop.
Methods
Included Modules
- MonitorMixin
Public Class methods
[ show source ]
# File lib/facets/more/pool.rb, line 38 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.
[ show source ]
# File lib/facets/more/pool.rb, line 64 def obtain result = nil begin obj = pop() result = yield(obj) ensure push(obj) end return result end
Obtain an object from the pool.
[ show source ]
# File lib/facets/more/pool.rb, line 54 def pop synchronize do @cv.wait_while { empty? } super end end
Add, restore an object to the pool.
[ show source ]
# File lib/facets/more/pool.rb, line 45 def push(obj) synchronize do super @cv.signal() end end