Pool

Generalized object pool implementation. Implemented as a thread safe stack. Exclusive locking is needed both for push and pop.

Methods
Included Modules
Public Class methods
new()
# File lib/facets/pool.rb, line 39
  def initialize
    super
    @cv = new_cond()
  end
Public Instance methods
obtain() {|obj| ...}

Obtains an object, passes it to a block for processing and restores it to the pool.

# File lib/facets/pool.rb, line 65
  def obtain
    result = nil
    begin
      obj = pop()
      result = yield(obj)
    ensure
      push(obj)
    end
    return result
  end
pop()

Obtain an object from the pool.

# File lib/facets/pool.rb, line 55
  def pop
    synchronize do
      @cv.wait_while { empty? }
      super
    end
  end
push(obj)

Add, restore an object to the pool.

# File lib/facets/pool.rb, line 46
  def push(obj)
    synchronize do
      super
      @cv.signal()
    end
  end