Sha256: a72a30b9a2e4f49a3cc8e7cf7df3d88bd474a61b0685990a0c8bfb6b22ec909b

Contents?: true

Size: 483 Bytes

Versions: 12

Compression:

Stored size: 483 Bytes

Contents

module Pallets
  class Pool
    def initialize(size)
      raise ArgumentError, 'Pool needs a block to initialize' unless block_given?

      @queue = Queue.new
      @size = size
      size.times { @queue << yield }
    end

    def size
      @queue.size
    end

    def execute
      raise ArgumentError, 'Pool needs a block to execute' unless block_given?

      begin
        item = @queue.pop
        yield item
      ensure
        @queue << item
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pallets-0.11.0 lib/pallets/pool.rb
pallets-0.10.0 lib/pallets/pool.rb
pallets-0.9.0 lib/pallets/pool.rb
pallets-0.8.0 lib/pallets/pool.rb
pallets-0.7.0 lib/pallets/pool.rb
pallets-0.6.0 lib/pallets/pool.rb
pallets-0.5.1 lib/pallets/pool.rb
pallets-0.5.0 lib/pallets/pool.rb
pallets-0.4.0 lib/pallets/pool.rb
pallets-0.3.0 lib/pallets/pool.rb
pallets-0.2.0 lib/pallets/pool.rb
pallets-0.1.0 lib/pallets/pool.rb