EM :: Iterator的工作示例

cmh*_*bbs 5 ruby iteration eventmachine

有没有人有EM :: Iterator的任何工作示例?我能找到的唯一例子似乎是(或指向)的副本:

http://yardoc.org/docs/eventmachine-eventmachine/EventMachine/Iterator

我没有在EventMachine的Rdoc中看到任何EM :: Iterator的实例,所以我不确定它是否是一个已删除的旧类.当我尝试使用EM :: Iterator时,我通常会收到以下错误:

NameError:未初始化的常量EventMachine :: Iterator

谢谢!

Art*_*ken 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
...
Run Code Online (Sandbox Code Playgroud)

EM::Iterator在Aman Gupta的优秀演示文稿EventMachine中还有一些幻灯片:红宝石中的可扩展非阻塞i/o,第46-50页.