lib/em-synchrony/em-multi.rb in em-synchrony-0.1.5 vs lib/em-synchrony/em-multi.rb in em-synchrony-0.2.0

- old
+ new

@@ -11,26 +11,30 @@ end def add(name, conn) fiber = Fiber.current conn.callback { @responses[:callback][name] = conn; check_progress(fiber) } - conn.errback { @responses[:errback][name] = conn; check_progress(fiber) } + conn.errback { @responses[:errback][name] = conn; check_progress(fiber) } @requests.push(conn) end + def finished? + (@responses[:callback].size + @responses[:errback].size) == @requests.size + end + def perform - Fiber.yield + Fiber.yield unless finished? end protected def check_progress(fiber) - if (@responses[:callback].size + @responses[:errback].size) == @requests.size + if finished? succeed # continue processing - fiber.resume(self) + fiber.resume(self) if fiber.alive? && fiber != Fiber.current end end end end end