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

Version Path
launchdarkly-server-sdk-8.8.2 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.8.1 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.8.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.7.1 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.7.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.6.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.5.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.4.2 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.4.1 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.4.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.3.1 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-7.3.3 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.3.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.2.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.1.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-7.3.2 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-8.0.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-7.3.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-7.2.0 lib/ldclient-rb/impl/unbounded_pool.rb
launchdarkly-server-sdk-7.1.0 lib/ldclient-rb/impl/unbounded_pool.rb