class LaunchDarkly::Impl::UnboundedPool

A simple thread safe generic unbounded resource pool abstraction

Public Class Methods

new(instance_creator, instance_destructor) click to toggle source
# File lib/ldclient-rb/impl/unbounded_pool.rb, line 5
def initialize(instance_creator, instance_destructor)
  @pool = Array.new
  @lock = Mutex.new
  @instance_creator = instance_creator
  @instance_destructor = instance_destructor
end

Public Instance Methods

acquire() click to toggle source
# File lib/ldclient-rb/impl/unbounded_pool.rb, line 12
def acquire
  @lock.synchronize {
    if @pool.length == 0
      @instance_creator.call()
    else
      @pool.pop()
    end
  }
end
dispose_all() click to toggle source
# File lib/ldclient-rb/impl/unbounded_pool.rb, line 26
def dispose_all
  @lock.synchronize {
    @pool.map { |instance| @instance_destructor.call(instance) } if !@instance_destructor.nil?
    @pool.clear()
  }
end
release(instance) click to toggle source
# File lib/ldclient-rb/impl/unbounded_pool.rb, line 22
def release(instance)
  @lock.synchronize { @pool.push(instance) }
end