Sha256: 51942af43fddb32ed1280d793fc66ca36a3bac144255dc9770c32367a8b4083b

Contents?: true

Size: 1001 Bytes

Versions: 2

Compression:

Stored size: 1001 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 = @hub.transport_mapper.from_transport arguments
        @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

2 entries across 2 versions & 1 rubygems

Version Path
pipe_rpc-2.5.0 lib/pipe_rpc/hub_request.rb
pipe_rpc-2.4.0 lib/pipe_rpc/hub_request.rb