Skip to content

Commit 016bc66

Browse files
authored
Condense docstring formatting to make it less overbearing (#98)
1 parent c529eae commit 016bc66

2 files changed

Lines changed: 36 additions & 173 deletions

File tree

src/Streaming.jl

Lines changed: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -115,48 +115,27 @@ Start a client streaming gRPC request (multiple requests, single response).
115115
```julia
116116
using gRPCClient
117117
118-
# ============================================================================
119118
# Step 1: Initialize gRPC
120-
# ============================================================================
121-
# This must be called once before making any gRPC requests.
122119
grpc_init()
123120
124-
# ============================================================================
125-
# Step 2: Include Generated Protocol Buffer Bindings
126-
# ============================================================================
121+
# Step 2: Include generated Protocol Buffer bindings
127122
include("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
132125
client = 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
139128
request_c = Channel{TestRequest}(16)
140-
141-
# Send one or more requests through the channel
142129
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
143130
144-
# ============================================================================
145-
# Step 5: Initiate the Streaming Request
146-
# ============================================================================
131+
# Step 5: Initiate the streaming request
147132
req = 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)
154136
close(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
160139
test_response = grpc_async_await(client, req)
161140
```
162141
"""
@@ -196,52 +175,27 @@ Start a server streaming gRPC request (single request, multiple responses).
196175
```julia
197176
using gRPCClient
198177
199-
# ============================================================================
200178
# Step 1: Initialize gRPC
201-
# ============================================================================
202-
# This must be called once before making any gRPC requests.
203179
grpc_init()
204180
205-
# ============================================================================
206-
# Step 2: Include Generated Protocol Buffer Bindings
207-
# ============================================================================
181+
# Step 2: Include generated Protocol Buffer bindings
208182
include("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
213185
client = 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
220188
response_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)
237194
for test_response in response_c
238195
@info test_response
239196
end
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
245199
grpc_async_await(req)
246200
```
247201
"""
@@ -288,64 +242,33 @@ Start a bidirectional streaming gRPC request (multiple requests, multiple respon
288242
```julia
289243
using gRPCClient
290244
291-
# ============================================================================
292245
# Step 1: Initialize gRPC
293-
# ============================================================================
294-
# This must be called once before making any gRPC requests.
295246
grpc_init()
296247
297-
# ============================================================================
298-
# Step 2: Include Generated Protocol Buffer Bindings
299-
# ============================================================================
248+
# Step 2: Include generated Protocol Buffer bindings
300249
include("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
305252
client = 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)
312255
request_c = Channel{TestRequest}(16)
313256
response_c = Channel{TestResponse}(16)
314257
315-
# ============================================================================
316-
# Step 5: Initiate the Bidirectional Streaming Request
317-
# ============================================================================
258+
# Step 5: Initiate the bidirectional streaming request
318259
req = 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
328262
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
329-
330-
# Receive responses as they arrive
331263
for 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
336266
end
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
343269
close(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
349272
grpc_async_await(req)
350273
```
351274
"""

src/Unary.jl

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,23 @@ This is ideal when you need to send many requests in parallel and waiting on eac
1010
```julia
1111
using gRPCClient
1212
13-
# ============================================================================
14-
# Step 1: Initialize gRPC
15-
# ============================================================================
16-
# This must be called once before making any gRPC requests.
17-
# It initializes the underlying libcurl multi handle and other resources.
13+
# Step 1: Initialize gRPC (must be called once before making any gRPC requests)
1814
grpc_init()
1915
20-
# ============================================================================
21-
# Step 2: Include Generated Protocol Buffer Bindings
22-
# ============================================================================
23-
# These bindings define the message types (e.g., TestRequest, TestResponse)
24-
# and client stubs for your gRPC service. They are generated from .proto files.
16+
# Step 2: Include generated Protocol Buffer bindings
2517
include("test/gen/test/test_pb.jl")
2618
27-
# ============================================================================
28-
# Step 3: Create a Client for Your RPC Method
29-
# ============================================================================
30-
# The client is bound to a specific RPC method on your gRPC service.
31-
# Arguments: hostname, port
19+
# Step 3: Create a client for your RPC method (hostname, port)
3220
client = TestService_TestRPC_Client("localhost", 8001)
3321
34-
# ============================================================================
35-
# Step 4: Send Multiple Async Requests
36-
# ============================================================================
37-
# Use grpc_async_request when you want to send requests without blocking.
38-
# This is useful for sending many requests in parallel.
39-
40-
# Send all requests without waiting for responses
22+
# Step 4: Send all requests without waiting for responses
4123
requests = Vector{gRPCRequest}()
4224
for i in 1:10
43-
# Each request is sent immediately and returns a gRPCRequest handle
44-
push!(
45-
requests,
46-
grpc_async_request(client, TestRequest(1, zeros(UInt64, 1)))
47-
)
25+
push!(requests, grpc_async_request(client, TestRequest(1, zeros(UInt64, 1))))
4826
end
4927
50-
# ============================================================================
51-
# Step 5: Wait for and Process Responses
52-
# ============================================================================
53-
# Use grpc_async_await to retrieve the response when you need it.
28+
# Step 5: Wait for and process responses
5429
for request in requests
55-
# This blocks until the specific request completes
5630
response = grpc_async_await(client, request)
5731
@info response
5832
end
@@ -105,51 +79,28 @@ This has the advantage over the request / await patern in that you can handle re
10579
```julia
10680
using gRPCClient
10781
108-
# ============================================================================
10982
# Step 1: Initialize gRPC
110-
# ============================================================================
111-
# This must be called once before making any gRPC requests.
11283
grpc_init()
11384
114-
# ============================================================================
115-
# Step 2: Include Generated Protocol Buffer Bindings
116-
# ============================================================================
85+
# Step 2: Include generated Protocol Buffer bindings
11786
include("test/gen/test/test_pb.jl")
11887
119-
# ============================================================================
120-
# Step 3: Create a Client for Your RPC Method
121-
# ============================================================================
88+
# Step 3: Create a client
12289
client = TestService_TestRPC_Client("localhost", 8001)
12390
124-
# ============================================================================
125-
# Step 4: Create a Channel to Receive Responses
126-
# ============================================================================
127-
# Use the channel-based pattern when you want to process responses as soon
128-
# as they arrive, regardless of the order they were sent.
91+
# Step 4: Create a channel to receive responses (processes responses as they arrive, in any order)
12992
N = 10
13093
channel = Channel{gRPCAsyncChannelResponse{TestResponse}}(N)
13194
132-
# ============================================================================
133-
# Step 5: Send All Requests
134-
# ============================================================================
135-
# The index parameter allows you to track which request each response
136-
# corresponds to, since responses may arrive out of order.
95+
# Step 5: Send all requests (the index tracks which response corresponds to which request)
13796
for (index, request) in enumerate([TestRequest(i, zeros(UInt64, i)) for i in 1:N])
13897
grpc_async_request(client, request, channel, index)
13998
end
14099
141-
# ============================================================================
142-
# Step 6: Process Responses as They Arrive
143-
# ============================================================================
144-
# Responses are pushed to the channel as they complete. You can process
145-
# them immediately without waiting for all requests to finish first.
100+
# Step 6: Process responses as they arrive
146101
for i in 1:N
147102
cr = take!(channel)
148-
149-
# Check if an exception was thrown during the request
150103
!isnothing(cr.ex) && throw(cr.ex)
151-
152-
# Use the index to match responses to requests
153104
@assert length(cr.response.data) == cr.index
154105
end
155106
```
@@ -218,27 +169,16 @@ Use this when you want the simplest possible interface for a single request.
218169
```julia
219170
using gRPCClient
220171
221-
# ============================================================================
222172
# Step 1: Initialize gRPC
223-
# ============================================================================
224-
# This must be called once before making any gRPC requests.
225173
grpc_init()
226174
227-
# ============================================================================
228-
# Step 2: Include Generated Protocol Buffer Bindings
229-
# ============================================================================
175+
# Step 2: Include generated Protocol Buffer bindings
230176
include("test/gen/test/test_pb.jl")
231177
232-
# ============================================================================
233-
# Step 3: Create a Client for Your RPC Method
234-
# ============================================================================
178+
# Step 3: Create a client
235179
client = TestService_TestRPC_Client("localhost", 8001)
236180
237-
# ============================================================================
238-
# Step 4: Make a Synchronous Request
239-
# ============================================================================
240-
# This blocks until the response is ready. It's the simplest way to make
241-
# a single gRPC request when you don't need parallelism.
181+
# Step 4: Make a synchronous request (blocks until response is ready)
242182
response = grpc_sync_request(client, TestRequest(1, zeros(UInt64, 1)))
243183
@info response
244184
```

0 commit comments

Comments
 (0)