Class: DelayIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/librr/delay_iterator.rb

Instance Method Summary collapse

Constructor Details

#initialize(iter) ⇒ DelayIterator

Returns a new instance of DelayIterator.



2
3
4
# File 'lib/librr/delay_iterator.rb', line 2

def initialize(iter)
  @iter = iter
end

Instance Method Details

#each(proc, finished = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/librr/delay_iterator.rb', line 6

def each(proc, finished=nil)
  do_work = proc {
    begin
      item = @iter.next
      proc.call(item)
      EM.next_tick(&do_work)
    rescue StopIteration
      finished.call if finished
    end
  }
  EM.next_tick(&do_work)
end