4040 */
4141
4242import Foundation
43+ import Dispatch
4344import gRPC
4445
45-
4646/// Type for errors thrown from generated client code.
4747public enum Echo_EchoClientError : Error {
4848 case endOfStream
@@ -61,7 +61,7 @@ public class Echo_EchoGetCall {
6161 /// Run the call. Blocks until the reply is received.
6262 fileprivate func run( request: Echo_EchoRequest ,
6363 metadata: Metadata ) throws -> Echo_EchoResponse {
64- let latch = CountDownLatch ( 1 )
64+ let sem = DispatchSemaphore ( value : 0 )
6565 var callResult : CallResult !
6666 var response : Echo_EchoResponse ?
6767 let requestData = try request. serializeProtobuf ( )
@@ -73,9 +73,9 @@ public class Echo_EchoGetCall {
7373 if let responseData = callResult. resultData {
7474 response = try ? Echo_EchoResponse ( protobuf: responseData)
7575 }
76- latch . signal ( )
76+ sem . signal ( )
7777 }
78- latch . wait ( )
78+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
7979 if let response = response {
8080 return response
8181 } else {
@@ -96,22 +96,22 @@ public class Echo_EchoExpandCall {
9696 // Call this once with the message to send.
9797 fileprivate func run( request: Echo_EchoRequest , metadata: Metadata ) throws -> Echo_EchoExpandCall {
9898 let requestData = try request. serializeProtobuf ( )
99- let latch = CountDownLatch ( 1 )
99+ let sem = DispatchSemaphore ( value : 0 )
100100 try call. start ( . serverStreaming,
101101 metadata: metadata,
102102 message: requestData)
103103 { callResult in
104- latch . signal ( )
104+ sem . signal ( )
105105 }
106- latch . wait ( )
106+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
107107 return self
108108 }
109109
110110 // Call this to wait for a result. Blocks.
111111 public func receive( ) throws -> Echo_EchoResponse {
112112 var returnError : Echo_EchoClientError ?
113113 var response : Echo_EchoResponse !
114- let latch = CountDownLatch ( 1 )
114+ let sem = DispatchSemaphore ( value : 0 )
115115 do {
116116 try call. receiveMessage ( ) { ( responseData) in
117117 if let responseData = responseData {
@@ -122,9 +122,9 @@ public class Echo_EchoExpandCall {
122122 } else {
123123 returnError = Echo_EchoClientError . endOfStream
124124 }
125- latch . signal ( )
125+ sem . signal ( )
126126 }
127- latch . wait ( )
127+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
128128 }
129129 if let returnError = returnError {
130130 throw returnError
@@ -144,13 +144,13 @@ public class Echo_EchoCollectCall {
144144
145145 // Call this to start a call.
146146 fileprivate func run( metadata: Metadata ) throws -> Echo_EchoCollectCall {
147- let latch = CountDownLatch ( 1 )
147+ let sem = DispatchSemaphore ( value : 0 )
148148 try self . call. start ( . clientStreaming,
149149 metadata: metadata)
150150 { callResult in
151- latch . signal ( )
151+ sem . signal ( )
152152 }
153- latch . wait ( )
153+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
154154 return self
155155 }
156156
@@ -164,7 +164,7 @@ public class Echo_EchoCollectCall {
164164 public func closeAndReceive( ) throws -> Echo_EchoResponse {
165165 var returnError : Echo_EchoClientError ?
166166 var returnResponse : Echo_EchoResponse !
167- let latch = CountDownLatch ( 1 )
167+ let sem = DispatchSemaphore ( value : 0 )
168168 do {
169169 try call. receiveMessage ( ) { ( responseData) in
170170 if let responseData = responseData,
@@ -173,10 +173,10 @@ public class Echo_EchoCollectCall {
173173 } else {
174174 returnError = Echo_EchoClientError . invalidMessageReceived
175175 }
176- latch . signal ( )
176+ sem . signal ( )
177177 }
178178 try call. close ( completion: { } )
179- latch . wait ( )
179+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
180180 } catch ( let error) {
181181 throw error
182182 }
@@ -197,20 +197,20 @@ public class Echo_EchoUpdateCall {
197197 }
198198
199199 fileprivate func run( metadata: Metadata ) throws -> Echo_EchoUpdateCall {
200- let latch = CountDownLatch ( 1 )
200+ let sem = DispatchSemaphore ( value : 0 )
201201 try self . call. start ( . bidiStreaming,
202202 metadata: metadata)
203203 { callResult in
204- latch . signal ( )
204+ sem . signal ( )
205205 }
206- latch . wait ( )
206+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
207207 return self
208208 }
209209
210210 public func receive( ) throws -> Echo_EchoResponse {
211211 var returnError : Echo_EchoClientError ?
212212 var returnMessage : Echo_EchoResponse !
213- let latch = CountDownLatch ( 1 )
213+ let sem = DispatchSemaphore ( value : 0 )
214214 do {
215215 try call. receiveMessage ( ) { ( data) in
216216 if let data = data {
@@ -221,9 +221,9 @@ public class Echo_EchoUpdateCall {
221221 } else {
222222 returnError = Echo_EchoClientError . endOfStream
223223 }
224- latch . signal ( )
224+ sem . signal ( )
225225 }
226- latch . wait ( )
226+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
227227 }
228228 if let returnError = returnError {
229229 throw returnError
@@ -237,11 +237,11 @@ public class Echo_EchoUpdateCall {
237237 }
238238
239239 public func closeSend( ) throws {
240- let latch = CountDownLatch ( 1 )
240+ let sem = DispatchSemaphore ( value : 0 )
241241 try call. close ( ) {
242- latch . signal ( )
242+ sem . signal ( )
243243 }
244- latch . wait ( )
244+ _ = sem . wait ( timeout : DispatchTime . distantFuture )
245245 }
246246}
247247
@@ -301,4 +301,4 @@ public class Echo_EchoService {
301301 public func update( ) throws -> Echo_EchoUpdateCall {
302302 return try Echo_EchoUpdateCall ( channel) . run ( metadata: metadata)
303303 }
304- }
304+ }
0 commit comments