5

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 try to use EM::Iterator:

NameError: uninitialized constant EventMachine::Iterator

Thanks!

4

1 回答 1

6

问题是最新发布的 EventMachine 版本是 0.12.10,现在已经 10 个月大了。EM::Iterator在该版本之后似乎已添加到代码库中;要使用它,您需要使用EventMachine 的开发版本

以下对我有用:

$ 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
...

EM::Iterator在 Aman Gupta 的出色演示EventMachine中也有一些幻灯片:ruby 中的可扩展非阻塞 i/o,第 46-50 页。

于 2010-08-02T19:53:01.987 回答