Skip to content

Commit

Permalink
fix nasty 100% cpu bug in EM::Iterator + add some debugging output
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed May 28, 2010
1 parent 650ff5e commit 544f82e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/em/iterator.rb
Expand Up @@ -95,6 +95,7 @@ def each(foreach=nil, after=nil, &blk)
}

@process_next = proc{
# p [:process_next, :pending=, @pending, :workers=, @workers, :ended=, @ended, :concurrency=, @concurrency, :list=, @list]
unless @ended or @workers > @concurrency
if @list.empty?
@ended = true
Expand Down Expand Up @@ -211,7 +212,8 @@ def next
#
def spawn_workers
EM.next_tick(start_worker = proc{
if @workers < @concurrency
if @workers < @concurrency and !@ended
# p [:spawning_worker, :workers=, @workers, :concurrency=, @concurrency, :ended=, @ended]
@workers += 1
@process_next.call
EM.next_tick(start_worker)
Expand All @@ -234,6 +236,7 @@ def spawn_workers

EM.run{
EM::Iterator.new(1..50).each{ |num,iter| p num; iter.next }
EM::Iterator.new([1,2,3], 10).each{ |num,iter| p num; iter.next }

i = EM::Iterator.new(1..100, 5)
i.each(proc{|num,iter|
Expand Down

0 comments on commit 544f82e

Please sign in to comment.