Sha256: 364a26c872ac19b12dd52dd011dd39d2ebb7c2aeced67a068855442b70cd269b
Contents?: true
Size: 829 Bytes
Versions: 4
Compression:
Stored size: 829 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 perform Fiber.yield end protected def check_progress(fiber) if (@responses[:callback].size + @responses[:errback].size) == @requests.size succeed # continue processing fiber.resume(self) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems