Skip to content

Commit

Permalink
+ explicitly tell Picky not to get more elements
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Oct 11, 2011
1 parent a4038d1 commit 89d8b19
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions server/lib/picky/cores.rb
Expand Up @@ -37,23 +37,28 @@ def self.forked ary_or_generator, options = {}, &block
# Get the maximum number of processors.
#
max = max_processors options
has_next = true
currently_processing = 0

#
#
loop do
# Ramp it up to num processors.
# Ramp it up to num processors or the amount
# of available things to work on.
#
while currently_processing < max
currently_processing += 1

while has_next && currently_processing < max
# Get the next thing to work on.
#
element = next_from generator

# If there is none, stop getting more.
#
break unless element
unless element
has_next = false
break
end

currently_processing += 1

# Fork and yield.
#
Expand All @@ -68,7 +73,7 @@ def self.forked ary_or_generator, options = {}, &block
begin
Process.wait 0
rescue Errno::ECHILD => e
break # Stop looping.
break
ensure
currently_processing -= 1
end
Expand Down

0 comments on commit 89d8b19

Please sign in to comment.