Sha256: 75f0c654a263c9f1b7af1ae462959bb3a6247b5c800e3d731b69d904a79ae35f

Contents?: true

Size: 997 Bytes

Versions: 4

Compression:

Stored size: 997 Bytes

Contents

class PipeRpc::Request; end

module PipeRpc
  class Hub::Request < Request
    def initialize(hub, body)
      @hub = hub
      super body
    end

    attr_reader :hub

    def handle
      evaluate_result do
        # the block is passed for asynchronous evaluation
        mapped_arguments = DeepMapper.from_transport(arguments, @hub)
        @hub.servers[server].__send__(method, *mapped_arguments, &evaluate_result_proc)
      end
    end
    CALL_FILE, CALL_LINENO = __FILE__, __LINE__-3

    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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pipe_rpc-2.2.3 lib/pipe_rpc/hub_request.rb
pipe_rpc-2.2.2 lib/pipe_rpc/hub_request.rb
pipe_rpc-2.2.1 lib/pipe_rpc/hub_request.rb
pipe_rpc-2.2.0 lib/pipe_rpc/hub_request.rb