@@ -18,7 +18,8 @@ import SwiftProtobuf
18
18
import SwiftProtobufPluginLibrary
19
19
20
20
extension Generator {
21
- internal func printClient( ) {
21
+ internal func printClient( asynchronousCode: Bool ,
22
+ synchronousCode: Bool ) {
22
23
for method in service. methods {
23
24
self . method = method
24
25
switch streamingType ( method) {
@@ -33,9 +34,11 @@ extension Generator {
33
34
}
34
35
}
35
36
println ( )
36
- printServiceClientProtocol ( )
37
+ printServiceClientProtocol ( asynchronousCode: asynchronousCode,
38
+ synchronousCode: synchronousCode)
37
39
println ( )
38
- printServiceClientImplementation ( )
40
+ printServiceClientImplementation ( asynchronousCode: asynchronousCode,
41
+ synchronousCode: synchronousCode)
39
42
if options. generateTestStubs {
40
43
println ( )
41
44
printServiceClientTestStubs ( )
@@ -144,18 +147,23 @@ extension Generator {
144
147
println ( )
145
148
}
146
149
147
- private func printServiceClientProtocol( ) {
150
+ private func printServiceClientProtocol( asynchronousCode: Bool ,
151
+ synchronousCode: Bool ) {
148
152
println ( " /// Instantiate \( serviceClassName) Client, then call methods of this protocol to make API calls. " )
149
153
println ( " \( options. visibility. sourceSnippet) protocol \( serviceClassName) : ServiceClient { " )
150
154
indent ( )
151
155
for method in service. methods {
152
156
self . method = method
153
157
switch streamingType ( method) {
154
158
case . unary:
155
- println ( " /// Synchronous. Unary. " )
156
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) " )
157
- println ( " /// Asynchronous. Unary. " )
158
- println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) " )
159
+ if synchronousCode {
160
+ println ( " /// Synchronous. Unary. " )
161
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) " )
162
+ }
163
+ if asynchronousCode {
164
+ println ( " /// Asynchronous. Unary. " )
165
+ println ( " func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) " )
166
+ }
159
167
case . serverStreaming:
160
168
println ( " /// Asynchronous. Server-streaming. " )
161
169
println ( " /// Send the initial message. " )
@@ -178,31 +186,36 @@ extension Generator {
178
186
println ( " } " )
179
187
}
180
188
181
- private func printServiceClientImplementation( ) {
189
+ private func printServiceClientImplementation( asynchronousCode: Bool ,
190
+ synchronousCode: Bool ) {
182
191
println ( " \( access) final class \( serviceClassName) Client: ServiceClientBase, \( serviceClassName) { " )
183
192
indent ( )
184
193
for method in service. methods {
185
194
self . method = method
186
195
switch streamingType ( method) {
187
196
case . unary:
188
- println ( " /// Synchronous. Unary. " )
189
- println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) { " )
190
- indent ( )
191
- println ( " return try \( callName) Base(channel) " )
192
- indent ( )
193
- println ( " .run(request: request, metadata: metadata) " )
194
- outdent ( )
195
- outdent ( )
196
- println ( " } " )
197
- println ( " /// Asynchronous. Unary. " )
198
- println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
199
- indent ( )
200
- println ( " return try \( callName) Base(channel) " )
201
- indent ( )
202
- println ( " .start(request: request, metadata: metadata, completion: completion) " )
203
- outdent ( )
204
- outdent ( )
205
- println ( " } " )
197
+ if synchronousCode {
198
+ println ( " /// Synchronous. Unary. " )
199
+ println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) ) throws -> \( methodOutputName) { " )
200
+ indent ( )
201
+ println ( " return try \( callName) Base(channel) " )
202
+ indent ( )
203
+ println ( " .run(request: request, metadata: metadata) " )
204
+ outdent ( )
205
+ outdent ( )
206
+ println ( " } " )
207
+ }
208
+ if asynchronousCode {
209
+ println ( " /// Asynchronous. Unary. " )
210
+ println ( " \( access) func \( methodFunctionName) (_ request: \( methodInputName) , completion: @escaping ( \( methodOutputName) ?, CallResult) -> Void) throws -> \( callName) { " )
211
+ indent ( )
212
+ println ( " return try \( callName) Base(channel) " )
213
+ indent ( )
214
+ println ( " .start(request: request, metadata: metadata, completion: completion) " )
215
+ outdent ( )
216
+ outdent ( )
217
+ println ( " } " )
218
+ }
206
219
case . serverStreaming:
207
220
println ( " /// Asynchronous. Server-streaming. " )
208
221
println ( " /// Send the initial message. " )
0 commit comments