0

I'm trying to get this code to work using em-synchrony 1.0.1.

require "em-synchrony"
class Worker
  attr_reader :station_queue, :list
  def initialize
    @station_queue = EM::Queue.new
    @list = ["value"] * 100
  end

  def run!
    station_queue.push(*list)
    station_popper = proc do |station|
      # Do some work with #{station}
      station_queue.pop(station_popper)
    end

    station_queue.pop(station_popper)
  end
end

EM::synchrony { Worker.new.run! }

The problem is that I'm getting a ruby-1.9.2-p290/gems/em-synchrony-1.0.1/lib/em-synchrony.rb:26: stack level too deep (SystemStackError) error. Is there a way to pop each item from a list like this without getting a stackoverflow error?

Linus Oleander
  • 17,746
  • 15
  • 69
  • 102

1 Answers1

0

The problem is that fibers only can handle a 4kb stack. Processing a list of 100 items will cause it to stack over flow.

It looks like they're about it implement a re-sizeable stack for fiber. http://bugs.ruby-lang.org/issues/3187

Linus Oleander
  • 17,746
  • 15
  • 69
  • 102