Sha256: 9a3a3c5259876f049d6ad11f1a3d08e4ff9deed599d75631b616019d29cf4624
Contents?: true
Size: 937 Bytes
Versions: 3
Compression:
Stored size: 937 Bytes
Contents
module EventMachine module Synchrony class Multi include EventMachine::Deferrable attr_reader :requests, :responses def initialize @requests = [] @responses = {:callback => {}, :errback => {}} 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) } @requests.push(conn) end def finished? (@responses[:callback].size + @responses[:errback].size) == @requests.size end def perform Fiber.yield unless finished? end protected def check_progress(fiber) if finished? succeed # continue processing fiber.resume(self) if fiber.alive? && fiber != Fiber.current end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
em-synchrony-1.0.0 | lib/em-synchrony/em-multi.rb |
em-synchrony-0.3.0.beta.1 | lib/em-synchrony/em-multi.rb |
em-synchrony-0.2.0 | lib/em-synchrony/em-multi.rb |