Sha256: 40db89802b94e5b74126d5a5defac121185be47aab5275a31cfe4f882d65eb74

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

require 'grpc'
require_relative 'cacheclient_pb'

module Momento
  # Builds SetResponses
  #
  # @private
  class SetResponseBuilder < ResponseBuilder
    # Build a Momento::SetResponse from a block of code
    # which returns a Momento::CacheClient::SetResponse..
    #
    # @return [Momento::SetResponse]
    # @raise [StandardError] when the exception is not recognized.
    # @raise [TypeError] when the response is not recognized.
    def from_block
      response = yield
    rescue *RESCUED_EXCEPTIONS => e
      SetResponse::Error.new(exception: e, context: context)
    else
      raise TypeError unless response.is_a?(::Momento::CacheClient::SetResponse)

      SetResponse::Success.new(key: context[:key], value: context[:value])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
momento-0.2.0 lib/momento/set_response_builder.rb