Sha256: 4656efaaa0f296fd945da1f28143b274c3364e03a0d4db0805aeedc7ae4a38c9

Contents?: true

Size: 431 Bytes

Versions: 13

Compression:

Stored size: 431 Bytes

Contents

# frozen_string_literal: true

module Relaton
  # Workers poll.
  class WorkersPool
    def initialize(workers = 2, &_block)
      num_workers = workers < 2 ? 2 : workers
      @queue = SizedQueue.new(num_workers * 2)
      @threads = Array.new num_workers do
        Thread.new do
          while item = @queue.pop; yield(item) end
        end
      end
    end

    def <<(item)
      @queue << item
      self
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
relaton-1.9.5 lib/relaton/workers_pool.rb
relaton-1.9.4 lib/relaton/workers_pool.rb
relaton-1.9.3 lib/relaton/workers_pool.rb
relaton-1.9.2 lib/relaton/workers_pool.rb
relaton-1.9.1 lib/relaton/workers_pool.rb
relaton-1.9.0 lib/relaton/workers_pool.rb
relaton-1.8.pre4 lib/relaton/workers_pool.rb
relaton-1.8.pre3 lib/relaton/workers_pool.rb
relaton-1.8.pre2 lib/relaton/workers_pool.rb
relaton-1.8.1 lib/relaton/workers_pool.rb
relaton-1.8.0 lib/relaton/workers_pool.rb
relaton-1.7.9 lib/relaton/workers_pool.rb
relaton-1.7.8 lib/relaton/workers_pool.rb