Sha256: f5596372db8474f2950c9dbef8ab702b7ed64310dfcab8ce95fb789a4530cb46

Contents?: true

Size: 866 Bytes

Versions: 5

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

require 'grpc_kit/interceptors'

module GrpcKit
  module Interceptors::Server
    class RequestResponse
      def initialize(interceptors)
        @interceptors = interceptors
      end

      def intercept(request, call, &block)
        if @interceptors && !@interceptors.empty?
          do_intercept(@interceptors.dup, request, call, &block)
        else
          yield(request, call)
        end
      end

      private

      def do_intercept(interceptors, request, call)
        if interceptors.empty?
          return yield(request, call)
        end

        interceptor = interceptors.pop
        interceptor.request_response(request: request, call: call, method: call.method) do
          do_intercept(interceptors, request, call) do |req, c|
            yield(req, c)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grpc_kit-0.1.8 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.1.7 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.1.6 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.1.5 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.1.4 lib/grpc_kit/interceptors/server_request_response.rb