Skip to content

Commit c693ebc

Browse files
[async-await] Code generation for "simple, but safe" wrapper client calls. (#1261)
This PR adds codegen support for the "simple, but safe wrappers" that were part of the proposal for async/await support, added in #1231. Codegen has also been re-run for the example Echo service.
1 parent 2f577e5 commit c693ebc

File tree

6 files changed

+505
-10
lines changed

6 files changed

+505
-10
lines changed

Sources/Examples/Echo/Model/echo.grpc.swift

+69
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,75 @@ extension Echo_EchoAsyncClientProtocol {
248248
}
249249
}
250250

251+
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
252+
extension Echo_EchoAsyncClientProtocol {
253+
public func get(
254+
_ request: Echo_EchoRequest,
255+
callOptions: CallOptions? = nil
256+
) async throws -> Echo_EchoResponse {
257+
return try await self.performAsyncUnaryCall(
258+
path: "/echo.Echo/Get",
259+
request: request,
260+
callOptions: callOptions ?? self.defaultCallOptions
261+
)
262+
}
263+
264+
public func expand(
265+
_ request: Echo_EchoRequest,
266+
callOptions: CallOptions? = nil
267+
) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
268+
return self.performAsyncServerStreamingCall(
269+
path: "/echo.Echo/Expand",
270+
request: request,
271+
callOptions: callOptions ?? self.defaultCallOptions
272+
)
273+
}
274+
275+
public func collect<RequestStream>(
276+
_ requests: RequestStream,
277+
callOptions: CallOptions? = nil
278+
) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
279+
return try await self.performAsyncClientStreamingCall(
280+
path: "/echo.Echo/Collect",
281+
requests: requests,
282+
callOptions: callOptions ?? self.defaultCallOptions
283+
)
284+
}
285+
286+
public func collect<RequestStream>(
287+
_ requests: RequestStream,
288+
callOptions: CallOptions? = nil
289+
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
290+
return try await self.performAsyncClientStreamingCall(
291+
path: "/echo.Echo/Collect",
292+
requests: requests,
293+
callOptions: callOptions ?? self.defaultCallOptions
294+
)
295+
}
296+
297+
public func update<RequestStream>(
298+
_ requests: RequestStream,
299+
callOptions: CallOptions? = nil
300+
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
301+
return self.performAsyncBidirectionalStreamingCall(
302+
path: "/echo.Echo/Update",
303+
requests: requests,
304+
callOptions: callOptions ?? self.defaultCallOptions
305+
)
306+
}
307+
308+
public func update<RequestStream>(
309+
_ requests: RequestStream,
310+
callOptions: CallOptions? = nil
311+
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
312+
return self.performAsyncBidirectionalStreamingCall(
313+
path: "/echo.Echo/Update",
314+
requests: requests,
315+
callOptions: callOptions ?? self.defaultCallOptions
316+
)
317+
}
318+
}
319+
251320
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
252321
public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
253322
public var channel: GRPCChannel

Sources/GRPC/AsyncAwaitSupport/GRPCChannel+AsyncAwaitSupport.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension GRPCChannel {
2626
/// - request: The request to send.
2727
/// - callOptions: Options for the RPC.
2828
/// - interceptors: A list of interceptors to intercept the request and response stream with.
29-
public func makeAsyncUnaryCall<Request: Message, Response: Message>(
29+
internal func makeAsyncUnaryCall<Request: Message, Response: Message>(
3030
path: String,
3131
request: Request,
3232
callOptions: CallOptions,
@@ -50,7 +50,7 @@ extension GRPCChannel {
5050
/// - request: The request to send.
5151
/// - callOptions: Options for the RPC.
5252
/// - interceptors: A list of interceptors to intercept the request and response stream with.
53-
public func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
53+
internal func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
5454
path: String,
5555
request: Request,
5656
callOptions: CallOptions,
@@ -73,7 +73,7 @@ extension GRPCChannel {
7373
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
7474
/// - callOptions: Options for the RPC.
7575
/// - interceptors: A list of interceptors to intercept the request and response stream with.
76-
public func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
76+
internal func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
7777
path: String,
7878
callOptions: CallOptions,
7979
interceptors: [ClientInterceptor<Request, Response>] = []
@@ -94,7 +94,7 @@ extension GRPCChannel {
9494
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
9595
/// - callOptions: Options for the RPC.
9696
/// - interceptors: A list of interceptors to intercept the request and response stream with.
97-
public func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
97+
internal func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
9898
path: String,
9999
callOptions: CallOptions,
100100
interceptors: [ClientInterceptor<Request, Response>] = []
@@ -116,7 +116,7 @@ extension GRPCChannel {
116116
/// - request: The request to send.
117117
/// - callOptions: Options for the RPC.
118118
/// - interceptors: A list of interceptors to intercept the request and response stream with.
119-
public func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
119+
internal func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
120120
path: String,
121121
request: Request,
122122
callOptions: CallOptions,
@@ -140,7 +140,7 @@ extension GRPCChannel {
140140
/// - request: The request to send.
141141
/// - callOptions: Options for the RPC.
142142
/// - interceptors: A list of interceptors to intercept the request and response stream with.
143-
public func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
143+
internal func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
144144
path: String,
145145
request: Request,
146146
callOptions: CallOptions,
@@ -163,7 +163,7 @@ extension GRPCChannel {
163163
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
164164
/// - callOptions: Options for the RPC.
165165
/// - interceptors: A list of interceptors to intercept the request and response stream with.
166-
public func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
166+
internal func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
167167
path: String,
168168
callOptions: CallOptions,
169169
interceptors: [ClientInterceptor<Request, Response>] = []
@@ -184,7 +184,7 @@ extension GRPCChannel {
184184
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
185185
/// - callOptions: Options for the RPC.
186186
/// - interceptors: A list of interceptors to intercept the request and response stream with.
187-
public func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
187+
internal func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
188188
path: String,
189189
callOptions: CallOptions,
190190
interceptors: [ClientInterceptor<Request, Response>] = []

0 commit comments

Comments
 (0)