Class: Gem::Mirror::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/mirror/pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Pool

Returns a new instance of Pool.



4
5
6
7
# File 'lib/rubygems/mirror/pool.rb', line 4

def initialize(size)
  @size = size
  @queue = Queue.new
end

Instance Method Details

#job(&blk) ⇒ Object



9
10
11
# File 'lib/rubygems/mirror/pool.rb', line 9

def job(&blk)
  @queue << blk
end

#run_til_doneObject



13
14
15
16
17
18
19
20
21
# File 'lib/rubygems/mirror/pool.rb', line 13

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