Module: Sfdown::Pool
- Defined in:
- lib/sfdown.rb
Overview
Runs a fixed pool of worker threads over a Queue, one item per call, until the queue is closed and drained.
Class Method Summary collapse
Class Method Details
.run(queue, workers, &blk) ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/sfdown.rb', line 183 def run(queue, workers, &blk) Array.new([workers, 1].max) do Thread.new do while (item = queue.pop) blk.call(item) end end end.each(&:join) end |