Module: Enumerable
- Defined in:
- lib/parl.rb
Instance Method Summary collapse
Instance Method Details
#parl(n) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/parl.rb', line 4 def parl (n) todo = Queue.new ts = (1..n).map { Thread.new { while x = todo.deq yield x[0] end } } each{|x| todo << [x]} n.times{ todo << nil } ts.each{|t| t.join} end |