We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1f1d2b4 + 6e3c168 commit 25c7cfdCopy full SHA for 25c7cfd
rakelib/lex.rake
@@ -62,11 +62,10 @@ module Prism
62
def parallelize(items, &block)
63
Thread.abort_on_exception = true
64
65
- queue = Queue.new
66
- items.each { |item| queue << item }
+ queue = Queue.new(items).close
67
68
workers =
69
- ENV.fetch("WORKERS") { 16 }.to_i.times.map do
+ ENV.fetch("WORKERS", "16").to_i.times.map do
70
parallelize_thread(queue, &block)
71
end
72
@@ -77,7 +76,11 @@ module Prism
77
76
78
# Create a new thread with a minimal number of locals that it can access.
79
def parallelize_thread(queue, &block)
80
- Thread.new { block.call(queue.shift) until queue.empty? }
+ Thread.new do
+ while item = queue.pop
81
+ block.call(item)
82
+ end
83
84
85
86
0 commit comments