class PipeRpc::Request; end module PipeRpc class Hub::Request < Request def initialize(hub, body) @hub = hub super body end CALL_FILE, CALL_LINENO = __FILE__, __LINE__+4 def handle evaluate_result do # the block is passed for asynchronous evaluation @hub.servers[server].__send__(method, *arguments, &evaluate_result_proc) end end def evaluate_result(result = nil, &block) result = Result.new(self, block_given? ? yield : result) rescue Exception => e result = ErrorResult.new(self, e) ensure asynchronous = result.value == evaluate_result_proc @hub.socket.write(result.to_response) unless asynchronous return result.value end def evaluate_result_proc @evaluate_result_proc ||= proc do |result = nil, &block| evaluate_result(result, &block) end end end end