Class: Gem::MiniMirror::Pool
- Inherits:
-
Object
- Object
- Gem::MiniMirror::Pool
- Defined in:
- lib/rubygems/mini_mirror/pool.rb
Instance Method Summary collapse
-
#initialize(size) ⇒ Pool
constructor
A new instance of Pool.
- #job(&blk) ⇒ Object
- #run_til_done ⇒ Object
Constructor Details
#initialize(size) ⇒ Pool
Returns a new instance of Pool.
3 4 5 6 |
# File 'lib/rubygems/mini_mirror/pool.rb', line 3 def initialize(size) @size = size @queue = Queue.new end |
Instance Method Details
#job(&blk) ⇒ Object
8 9 10 |
# File 'lib/rubygems/mini_mirror/pool.rb', line 8 def job(&blk) @queue << blk end |
#run_til_done ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rubygems/mini_mirror/pool.rb', line 12 def run_til_done threads = Array.new(@size) do Thread.new { @queue.pop.call while true } end until @queue.empty? && @queue.num_waiting == @size threads.each { |t| t.join(0.1) } end threads.each { |t| t.kill } end |