Method: EventMachine::Iterator#initialize
- Defined in:
- lib/em/iterator.rb
#initialize(list, concurrency = 1) ⇒ Iterator
Create a new parallel async iterator with specified concurrency.
i = EM::Iterator.new(1..100, 10)
will create an iterator over the range that processes 10 items at a time. Iteration is started via #each, #map or #inject
The list may either be an array-like object, or a proc that returns a new object to be processed each time it is called. If a proc is used, it must return EventMachine::Iterator::Stop to signal the end of the iterations.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/em/iterator.rb', line 56 def initialize(list, concurrency = 1) raise ArgumentError, 'concurrency must be bigger than zero' unless (concurrency > 0) if list.respond_to?(:call) @list = nil @list_proc = list elsif list.respond_to?(:to_a) @list = list.to_a.dup @list_proc = nil else raise ArgumentError, 'argument must be a proc or an array' end @concurrency = concurrency @started = false @ended = false end |