@@ -115,48 +115,27 @@ Start a client streaming gRPC request (multiple requests, single response).
115115```julia
116116using gRPCClient
117117
118- # ============================================================================
119118# Step 1: Initialize gRPC
120- # ============================================================================
121- # This must be called once before making any gRPC requests.
122119grpc_init()
123120
124- # ============================================================================
125- # Step 2: Include Generated Protocol Buffer Bindings
126- # ============================================================================
121+ # Step 2: Include generated Protocol Buffer bindings
127122include("test/gen/test/test_pb.jl")
128123
129- # ============================================================================
130- # Step 3: Create a Client for Your Streaming RPC Method
131- # ============================================================================
124+ # Step 3: Create a client
132125client = TestService_TestClientStreamRPC_Client("localhost", 8001)
133126
134- # ============================================================================
135- # Step 4: Create a Request Channel and Send Requests
136- # ============================================================================
137- # The channel buffers requests that will be streamed to the server.
138- # Buffer size of 16 means up to 16 requests can be queued.
127+ # Step 4: Create a request channel and send requests
139128request_c = Channel{TestRequest}(16)
140-
141- # Send one or more requests through the channel
142129put!(request_c, TestRequest(1, zeros(UInt64, 1)))
143130
144- # ============================================================================
145- # Step 5: Initiate the Streaming Request
146- # ============================================================================
131+ # Step 5: Initiate the streaming request
147132req = grpc_async_request(client, request_c)
148133
149- # ============================================================================
150- # Step 6: Close the Request Channel When Done
151- # ============================================================================
152- # IMPORTANT: You must close the channel to signal that no more requests
153- # will be sent. The server won't send the response until the stream ends.
134+ # Step 6: Close the channel to signal no more requests will be sent
135+ # (the server won't respond until the stream ends)
154136close(request_c)
155137
156- # ============================================================================
157- # Step 7: Wait for the Single Response
158- # ============================================================================
159- # After all requests are sent and processed, the server returns one response.
138+ # Step 7: Wait for the single response
160139test_response = grpc_async_await(client, req)
161140```
162141"""
@@ -196,52 +175,27 @@ Start a server streaming gRPC request (single request, multiple responses).
196175```julia
197176using gRPCClient
198177
199- # ============================================================================
200178# Step 1: Initialize gRPC
201- # ============================================================================
202- # This must be called once before making any gRPC requests.
203179grpc_init()
204180
205- # ============================================================================
206- # Step 2: Include Generated Protocol Buffer Bindings
207- # ============================================================================
181+ # Step 2: Include generated Protocol Buffer bindings
208182include("test/gen/test/test_pb.jl")
209183
210- # ============================================================================
211- # Step 3: Create a Client for Your Streaming RPC Method
212- # ============================================================================
184+ # Step 3: Create a client
213185client = TestService_TestServerStreamRPC_Client("localhost", 8001)
214186
215- # ============================================================================
216- # Step 4: Create a Response Channel
217- # ============================================================================
218- # The channel will receive multiple responses from the server.
219- # Buffer size of 16 means up to 16 responses can be queued.
187+ # Step 4: Create a response channel to receive multiple responses
220188response_c = Channel{TestResponse}(16)
221189
222- # ============================================================================
223- # Step 5: Initiate the Streaming Request
224- # ============================================================================
225- # Send a single request. The server will respond with multiple messages.
226- req = grpc_async_request(
227- client,
228- TestRequest(1, zeros(UInt64, 1)),
229- response_c,
230- )
231-
232- # ============================================================================
233- # Step 6: Process Streaming Responses
234- # ============================================================================
235- # Read responses from the channel as they arrive. The channel will be closed
236- # when the server finishes sending all responses.
190+ # Step 5: Send a single request (the server will respond with multiple messages)
191+ req = grpc_async_request(client, TestRequest(1, zeros(UInt64, 1)), response_c)
192+
193+ # Step 6: Process streaming responses (channel closes when server finishes)
237194for test_response in response_c
238195 @info test_response
239196end
240197
241- # ============================================================================
242- # Step 7: Check for Exceptions
243- # ============================================================================
244- # Call grpc_async_await to raise any exceptions that occurred during the request.
198+ # Step 7: Check for exceptions
245199grpc_async_await(req)
246200```
247201"""
@@ -288,64 +242,33 @@ Start a bidirectional streaming gRPC request (multiple requests, multiple respon
288242```julia
289243using gRPCClient
290244
291- # ============================================================================
292245# Step 1: Initialize gRPC
293- # ============================================================================
294- # This must be called once before making any gRPC requests.
295246grpc_init()
296247
297- # ============================================================================
298- # Step 2: Include Generated Protocol Buffer Bindings
299- # ============================================================================
248+ # Step 2: Include generated Protocol Buffer bindings
300249include("test/gen/test/test_pb.jl")
301250
302- # ============================================================================
303- # Step 3: Create a Client for Your Streaming RPC Method
304- # ============================================================================
251+ # Step 3: Create a client
305252client = TestService_TestBidirectionalStreamRPC_Client("localhost", 8001)
306253
307- # ============================================================================
308- # Step 4: Create Request and Response Channels
309- # ============================================================================
310- # Both channels allow streaming in both directions simultaneously.
311- # Buffer size of 16 means up to 16 messages can be queued in each direction.
254+ # Step 4: Create request and response channels (streaming in both directions simultaneously)
312255request_c = Channel{TestRequest}(16)
313256response_c = Channel{TestResponse}(16)
314257
315- # ============================================================================
316- # Step 5: Initiate the Bidirectional Streaming Request
317- # ============================================================================
258+ # Step 5: Initiate the bidirectional streaming request
318259req = grpc_async_request(client, request_c, response_c)
319260
320- # ============================================================================
321- # Step 6: Send Requests and Receive Responses Concurrently
322- # ============================================================================
323- # In bidirectional streaming, you can send and receive at the same time.
324- # This example shows a simple pattern, but you can use tasks for more
325- # complex concurrent communication patterns.
326-
327- # Send a request
261+ # Step 6: Send requests and receive responses concurrently
328262put!(request_c, TestRequest(1, zeros(UInt64, 1)))
329-
330- # Receive responses as they arrive
331263for test_response in response_c
332264 @info test_response
333- # Optionally send more requests based on responses
334- # put!(request_c, ...)
335265 break # Exit after first response for this example
336266end
337267
338- # ============================================================================
339- # Step 7: Close the Request Channel When Done
340- # ============================================================================
341- # IMPORTANT: You must close the request channel to signal that no more
342- # requests will be sent.
268+ # Step 7: Close the request channel to signal no more requests will be sent
343269close(request_c)
344270
345- # ============================================================================
346- # Step 8: Check for Exceptions
347- # ============================================================================
348- # Call grpc_async_await to raise any exceptions that occurred during the request.
271+ # Step 8: Check for exceptions
349272grpc_async_await(req)
350273```
351274"""
0 commit comments