class Gruf::Response

Wraps the active call operation to provide metadata and timing around the request

Attributes

cancelled[R]

@return [Boolean] Whether or not the operation was cancelled

deadline[R]

@return [Time] The set deadline on the call

execution_time[R]

@return [Float] The time that the request took to execute

metadata[R]

@return [Hash] The metadata that was attached to the operation

operation[R]

@return [GRPC::ActiveCall::Operation] The operation that was executed for the given request

trailing_metadata[R]

@return [Hash] The trailing metadata that the service returned

Public Class Methods

new(operation:, message:, execution_time: nil) click to toggle source

Initialize a response object with the given gRPC operation

@param [GRPC::ActiveCall::Operation] operation The given operation for the current call @param [StdClass] message @param [Float] execution_time The amount of time that the response took to occur

# File lib/gruf/response.rb, line 43
def initialize(operation:, message:, execution_time: nil)
  @operation = operation
  @message = message
  @metadata = operation.metadata
  @trailing_metadata = operation.trailing_metadata
  @deadline = operation.deadline
  @cancelled = operation.cancelled?
  @execution_time = execution_time || 0.0
end

Public Instance Methods

internal_execution_time() click to toggle source

Return execution time of the call internally on the server in ms

@return [Float] The execution time of the response

# File lib/gruf/response.rb, line 67
def internal_execution_time
  trailing_metadata['timer'].to_f
end
message() click to toggle source

Return the message returned by the request

@return [Object] The protobuf response message

# File lib/gruf/response.rb, line 58
def message
  @message ||= @operation.execute
end