Class: Redom::ThreadPool

Inherits:
Object
  • Object
show all
Defined in:
lib/redom/thread_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ThreadPool

Returns a new instance of ThreadPool.



3
4
5
6
7
8
9
# File 'lib/redom/thread_pool.rb', line 3

def initialize(opts)
  @workers = Array.new
  @idx = 0
  opts[:worker].times {
    @workers << Worker.new
  }
end

Instance Method Details

#startObject



11
12
13
14
15
# File 'lib/redom/thread_pool.rb', line 11

def start
  @workers.each { |worker|
    worker.start
  }
end

#stopObject



17
18
19
20
21
# File 'lib/redom/thread_pool.rb', line 17

def stop
  @workers.each { |worker|
    worker.stop
  }
end

#workerObject



23
24
25
# File 'lib/redom/thread_pool.rb', line 23

def worker
  @workers[(@idx += 1) == @workers.size ? @idx = 0 : @idx]
end