Class: Relaton::WorkersPool

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/workers_pool.rb

Overview

Workers poll.

Instance Method Summary collapse

Constructor Details

#initialize(workers = 2, &_block) ⇒ WorkersPool

Returns a new instance of WorkersPool.



6
7
8
9
10
11
12
13
14
# File 'lib/relaton/workers_pool.rb', line 6

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

Instance Method Details

#<<(item) ⇒ Object



16
17
18
19
# File 'lib/relaton/workers_pool.rb', line 16

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