Class: SimpleWorker::Worker

Inherits:
Queue
  • Object
show all
Defined in:
lib/simple-worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(num = 1) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple-worker.rb', line 5

def initialize(num = 1)
  super()
  @workers = []

  num.times do |i|
    @workers << Thread.start do
      loop do
        pop.call(i)
      end
    end
  end
end

Instance Method Details

#push(obj = nil, &block) ⇒ Object



18
19
20
# File 'lib/simple-worker.rb', line 18

def push(obj = nil, &block)
  super(obj || block)
end