@@ -113,11 +113,12 @@ def call(request)
113113 # @parameter metadata [Hash] Custom metadata headers
114114 # @parameter timeout [Numeric | Nil] Optional timeout in seconds
115115 # @parameter encoding [String | Nil] Optional compression encoding
116+ # @parameter initial [Object | Array | Nil] Optional initial message(s) for bidirectional streaming
116117 # @yields {|input, output| ...} Block for streaming calls
117118 # @returns [Object | Protocol::GRPC::Body::ReadableBody] Response message or readable body for streaming
118119 # @raises [ArgumentError] If method is unknown or streaming type is invalid
119120 # @raises [Protocol::GRPC::Error] If the gRPC call fails
120- def invoke ( service , method , request = nil , metadata : { } , timeout : nil , encoding : nil , &block )
121+ def invoke ( service , method , request = nil , metadata : { } , timeout : nil , encoding : nil , initial : nil , &block )
121122 rpc = service . class . lookup_rpc ( method )
122123 raise ArgumentError , "Unknown method: #{ method } " unless rpc
123124
@@ -141,7 +142,7 @@ def invoke(service, method, request = nil, metadata: {}, timeout: nil, encoding:
141142 when :client_streaming
142143 client_streaming_call ( path , headers , request_class , response_class , encoding , &block )
143144 when :bidirectional
144- bidirectional_call ( path , headers , request_class , response_class , encoding , &block )
145+ bidirectional_call ( path , headers , request_class , response_class , encoding , initial : initial , &block )
145146 else
146147 raise ArgumentError , "Unknown streaming type: #{ streaming } "
147148 end
@@ -273,14 +274,16 @@ def client_streaming_call(path, headers, request_class, response_class, encoding
273274 # @parameter request_class [Class] Request message class
274275 # @parameter response_class [Class] Response message class
275276 # @parameter encoding [String | Nil] Compression encoding
277+ # @parameter initial [Object | Array | Nil] Optional initial message(s) to write before waiting for the response
276278 # @yields {|input, output| ...} Block to handle bidirectional streaming
277279 # @returns [Protocol::GRPC::Body::ReadableBody] Readable body for streaming messages
278280 # @raises [Protocol::GRPC::Error] If the gRPC call fails
279- def bidirectional_call ( path , headers , request_class , response_class , encoding , &block )
281+ def bidirectional_call ( path , headers , request_class , response_class , encoding , initial : nil , &block )
280282 body = Protocol ::GRPC ::Body ::WritableBody . new (
281283 encoding : encoding ,
282284 message_class : request_class
283285 )
286+ Array ( initial ) . each { |message | body . write ( message ) }
284287
285288 http_request = Protocol ::HTTP ::Request [ "POST" , path , headers , body ]
286289 response = call ( http_request )
0 commit comments