Sha256: a2178109ed56ce8c79e5f41af33a8aa9752d8b8eea1df219e4661d5ac7879e0c

Contents?: true

Size: 425 Bytes

Versions: 41

Compression:

Stored size: 425 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(workers * 2)
      @threads = Array.new 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

41 entries across 41 versions & 1 rubygems

Version Path
relaton-1.20.0 lib/relaton/workers_pool.rb
relaton-1.19.2 lib/relaton/workers_pool.rb
relaton-1.19.1 lib/relaton/workers_pool.rb
relaton-1.19.0 lib/relaton/workers_pool.rb
relaton-1.18.2 lib/relaton/workers_pool.rb
relaton-1.18.1 lib/relaton/workers_pool.rb
relaton-1.18.0 lib/relaton/workers_pool.rb
relaton-1.17.2 lib/relaton/workers_pool.rb
relaton-1.17.1 lib/relaton/workers_pool.rb
relaton-1.17.0 lib/relaton/workers_pool.rb
relaton-1.16.1 lib/relaton/workers_pool.rb
relaton-1.16.0 lib/relaton/workers_pool.rb
relaton-1.15.6 lib/relaton/workers_pool.rb
relaton-1.15.5 lib/relaton/workers_pool.rb
relaton-1.15.4 lib/relaton/workers_pool.rb
relaton-1.15.3 lib/relaton/workers_pool.rb
relaton-1.15.2 lib/relaton/workers_pool.rb
relaton-1.15.1 lib/relaton/workers_pool.rb
relaton-1.15.0 lib/relaton/workers_pool.rb
relaton-1.14.2 lib/relaton/workers_pool.rb