class EventMachine::Synchrony::Iterator

Public Instance Methods

each(foreach=nil, after=nil, &blk) click to toggle source

synchronous iterator which will wait until all the jobs are done before returning. Unfortunately this means that you loose ability to choose concurrency on the fly (see iterator documentation in EM)

Calls superclass method
# File lib/em-synchrony/iterator.rb, line 12
def each(foreach=nil, after=nil, &blk)
  fiber = Fiber.current

  fe = (foreach || blk)
  cb = Proc.new do
    after.call if after
    fiber.resume
  end

  Fiber.yield super(fe, cb)
end
inject(obj, foreach = nil, after = nil, &block) click to toggle source
Calls superclass method
# File lib/em-synchrony/iterator.rb, line 35
def inject(obj, foreach = nil, after = nil, &block)
  if foreach and after
    super(obj, foreach, after)
  else
    fiber = Fiber.current
    result = nil

    after = Proc.new {|res| result = res; fiber.resume}
    super(obj, block, after)

    Fiber.yield
    result
  end
end
map(&block) click to toggle source
Calls superclass method
# File lib/em-synchrony/iterator.rb, line 24
def map(&block)
  fiber = Fiber.current
  result = nil

  after = Proc.new {|res| result = res; fiber.resume }
  super(block, after)

  Fiber.yield
  result
end