Sha256: 2d70bfe9e9045d88a04d8627362cac15c24acb06e0b278654511c7dd117b54aa
Contents?: true
Size: 841 Bytes
Versions: 25
Compression:
Stored size: 841 Bytes
Contents
module LaunchDarkly module Impl # A simple thread safe generic unbounded resource pool abstraction class UnboundedPool def initialize(instance_creator, instance_destructor) @pool = Array.new @lock = Mutex.new @instance_creator = instance_creator @instance_destructor = instance_destructor end def acquire @lock.synchronize { if @pool.length == 0 @instance_creator.call() else @pool.pop() end } end def release(instance) @lock.synchronize { @pool.push(instance) } end def dispose_all @lock.synchronize { @pool.map { |instance| @instance_destructor.call(instance) } unless @instance_destructor.nil? @pool.clear() } end end end end
Version data entries
25 entries across 25 versions & 1 rubygems