Does anyone have any working examples of EM::Iterator? The only examples I can find seem to be copies of (or point back to):
http://yardoc.org/docs/eventmachine-eventmachine/EventMachine/Iterator
I don't see any instances of EM::Iterator in EventMachine's Rdoc, so I'm not sure if it's an old class that has been removed or not. I generally get the following error when I t开发者_如何学编程ry to use EM::Iterator:
NameError: uninitialized constant EventMachine::Iterator
Thanks!
The problem is that the latest released EventMachine version is 0.12.10, which is now 10 months old. EM::Iterator
appears to have been added to the code base after that release; to utilize it, you will need to be using the development version of EventMachine.
The following worked for me:
$ git clone git://github.com/eventmachine/eventmachine.git
$ cd eventmachine
$ irb -Ilib -reventmachine
irb(main):001:0> EM.run do
irb(main):002:1* EM::Iterator.new(0..10, 2).each do |num, iter|
irb(main):003:2* puts num
irb(main):004:2> EM.add_timer(1) { iter.next }
irb(main):005:2> end
irb(main):006:1> end
...
There are also some slides relating to EM::Iterator
in Aman Gupta's excellent presentation EventMachine: scalable non-blocking i/o in ruby, pages 46-50.
精彩评论