Method: GRPC::ClientStub#server_streamer

Defined in:
src/ruby/lib/grpc/generic/client_stub.rb

#server_streamer(method, req, marshal, unmarshal, deadline: nil, return_op: false, parent: nil, credentials: nil, metadata: {}, &blk) ⇒ Enumerator|Operation|nil

server_streamer sends one request to the GRPC server, which yields a stream of responses.

responses provides an enumerator over the streamed responses, i.e. it follows Ruby’s #each iteration protocol. The enumerator blocks while waiting for each response, stops when the server signals that no further responses will be supplied. If the implicit block is provided, it is executed with each response as the argument and no result is returned.

Flow Control ==

This is a blocking call.

  • the request is sent only when GRPC core’s flow control allows it to be sent.

  • the request will not complete until the server sends the final response followed by a status message.

Errors ==

An RuntimeError is raised if

  • the server responds with a non-OK status when any response is

  • retrieved

  • the deadline is exceeded

Return Value ==

if the return_op is false, the return value is an Enumerator of the results, unless a block is provided, in which case the block is executed with each response.

if return_op is true, the function returns an Operation whose #execute method runs server streamer call. Again, Operation#execute either calls the given block with each response or returns an Enumerator of the responses.

Keyword Args ==

Unspecified keyword arguments are treated as metadata to be sent to the server.

Parameters:

  • method (String)

    the RPC method to call on the GRPC server

  • req (Object)

    the request sent to the server

  • marshal (Function)

    f(obj)->string that marshals requests

  • unmarshal (Function)

    f(string)->obj that unmarshals responses

  • deadline (Time) (defaults to: nil)

    (optional) the time the request should complete

  • return_op (true|false) (defaults to: false)

    return an Operation if true

  • parent (Core::Call) (defaults to: nil)

    a prior call whose reserved metadata will be propagated by this one.

  • credentials (Core::CallCredentials) (defaults to: nil)

    credentials to use when making the call

  • metadata (Hash) (defaults to: {})

    metadata to be sent to the server

  • blk (Block)

    when provided, is executed for each response

Returns:

  • (Enumerator|Operation|nil)

    as discussed above



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'src/ruby/lib/grpc/generic/client_stub.rb', line 318

def server_streamer(method, req, marshal, unmarshal,
                    deadline: nil,
                    return_op: false,
                    parent: nil,
                    credentials: nil,
                    metadata: {},
                    &blk)
  c = new_active_call(method, marshal, unmarshal,
                      deadline: deadline,
                      parent: parent,
                      credentials: credentials)
  interception_context = @interceptors.build_context
  intercept_args = {
    method: method,
    request: req,
    call: c.interceptable,
    metadata: 
  }
  if return_op
    # return the operation view of the active_call; define #execute
    # as a new method for this instance that invokes #server_streamer
    c.()
    op = c.operation
    op.define_singleton_method(:execute) do
      interception_context.intercept!(:server_streamer, intercept_args) do
        c.server_streamer(req, &blk)
      end
    end
    op
  else
    interception_context.intercept!(:server_streamer, intercept_args) do
      c.server_streamer(req, metadata: , &blk)
    end
  end
end