Skip to content

Commit

Permalink
[async-await] Code generation for "simple, but safe" wrapper client c…
Browse files Browse the repository at this point in the history
…alls. (#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.
  • Loading branch information
simonjbeaumont authored and glbrntt committed Sep 16, 2021
1 parent 15cabab commit c93075c
Show file tree
Hide file tree
Showing 6 changed files with 505 additions and 10 deletions.
69 changes: 69 additions & 0 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,75 @@ extension Echo_EchoAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension Echo_EchoAsyncClientProtocol {
public func get(
_ request: Echo_EchoRequest,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse {
return try await self.performAsyncUnaryCall(
path: "/echo.Echo/Get",
request: request,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func expand(
_ request: Echo_EchoRequest,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
return self.performAsyncServerStreamingCall(
path: "/echo.Echo/Expand",
request: request,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func collect<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
return try await self.performAsyncClientStreamingCall(
path: "/echo.Echo/Collect",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func collect<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
return try await self.performAsyncClientStreamingCall(
path: "/echo.Echo/Collect",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func update<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
return self.performAsyncBidirectionalStreamingCall(
path: "/echo.Echo/Update",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func update<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
return self.performAsyncBidirectionalStreamingCall(
path: "/echo.Echo/Update",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
public var channel: GRPCChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncUnaryCall<Request: Message, Response: Message>(
internal func makeAsyncUnaryCall<Request: Message, Response: Message>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -50,7 +50,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -73,7 +73,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -94,7 +94,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -116,7 +116,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -140,7 +140,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -163,7 +163,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -184,7 +184,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand Down
Loading

0 comments on commit c93075c

Please sign in to comment.