Class: Async::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/em-easy.rb

Instance Method Summary collapse

Methods included from Enumerable

#async

Constructor Details

#initialize(collection) ⇒ Enumerator

Returns a new instance of Enumerator.



15
16
17
18
# File 'lib/em-easy.rb', line 15

def initialize(collection)
  @collection = collection
  @total = collection.size
end

Instance Method Details

#each(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/em-easy.rb', line 20

def each(&block)
  @finished = 0
  @block = block
  iterate_collection = proc do
    @collection.each do |it|
      if it.respond_to? :callback
        it.callback {|result| finished result }
      else
        finished it
      end
    end
  end
  Async.evented_loop.resume :block => iterate_collection, :smart => true
end