Просмотр исходного кода

Replace calls to `DispatchSemaphore.wait(timeout: DispatchTime.distantFuture)` with just `.wait()`.

Daniel Alm 7 лет назад
Родитель
Сommit
cab578fbd2

+ 2 - 2
Examples/Echo/EchoProvider.swift

@@ -34,7 +34,7 @@ class EchoProvider: Echo_EchoProvider {
       response.text = "Swift echo expand (\(i)): \(part)"
       let sem = DispatchSemaphore(value: 0)
       try session.send(response) { _ in sem.signal() }
-      _ = sem.wait(timeout: DispatchTime.distantFuture)
+      _ = sem.wait()
       i += 1
     }
   }
@@ -68,7 +68,7 @@ class EchoProvider: Echo_EchoProvider {
         response.text = "Swift echo update (\(count)): \(request.text)"
         let sem = DispatchSemaphore(value: 0)
         try session.send(response) { _ in sem.signal() }
-        _ = sem.wait(timeout: DispatchTime.distantFuture)
+        _ = sem.wait()
       } catch ServerError.endOfStream {
         break
       } catch (let error) {

+ 4 - 4
Examples/Echo/PackageManager/Sources/main.swift

@@ -78,7 +78,7 @@ Group {
     }
     // This blocks to keep the main thread from finishing while the server runs,
     // but the server never exits. Kill the process to stop it.
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     // This suppresses a "variable echoServer was written to, but never read" warning.
     _ = echoServer
     // And this ensures that echoServer doesn't get deallocated right after it is created.
@@ -118,7 +118,7 @@ Group {
         running = false
       }
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     if let statusCode = callResult?.statusCode {
       print("expand completed with code \(statusCode)")
     }
@@ -164,7 +164,7 @@ Group {
     }
     let responseMessage = try collectCall.closeAndReceive()
     print("collect received: \(responseMessage.text)")
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     if let statusCode = callResult?.statusCode {
       print("collect completed with status \(statusCode)")
     }
@@ -226,7 +226,7 @@ Group {
     }
     try updateCall.closeSend()
 
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
 
     for response in responses {
       print(response)

+ 1 - 1
Examples/Google/NaturalLanguage/Sources/main.swift

@@ -64,7 +64,7 @@ if let provider = DefaultTokenProvider(scopes: scopes) {
     }
     sem.signal()
   }
-  _ = sem.wait(timeout: DispatchTime.distantFuture)
+  _ = sem.wait()
 } else {
   print("Unable to create default token provider.")
 }

+ 2 - 2
Examples/Simple/PackageManager/main.swift

@@ -57,7 +57,7 @@ func client() throws {
       }
       sem.signal()
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
   }
   print("Done")
 }
@@ -119,7 +119,7 @@ func server() throws {
     print("Server Stopped")
   }
 
-  _ = sem.wait(timeout: DispatchTime.distantFuture)
+  _ = sem.wait()
 }
 
 Group {

+ 2 - 2
Sources/gRPC/GenCodeSupport/ClientCallBidirectionalStreaming.swift

@@ -57,7 +57,7 @@ open class ClientCallBidirectionalStreamingBase<InputType: Message, OutputType:
         returnError = error
         sem.signal()
       }
-      _ = sem.wait(timeout: DispatchTime.distantFuture)
+      _ = sem.wait()
     }
     if let returnError = returnError {
       throw returnError
@@ -79,7 +79,7 @@ open class ClientCallBidirectionalStreamingBase<InputType: Message, OutputType:
     try closeSend {
       sem.signal()
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
   }
 
   public func cancel() {

+ 1 - 1
Sources/gRPC/GenCodeSupport/ClientCallClientStreaming.swift

@@ -63,7 +63,7 @@ open class ClientCallClientStreamingBase<InputType: Message, OutputType: Message
         returnError = error
         sem.signal()
       }
-      _ = sem.wait(timeout: DispatchTime.distantFuture)
+      _ = sem.wait()
     } catch (let error) {
       throw error
     }

+ 1 - 1
Sources/gRPC/GenCodeSupport/ClientCallServerStreaming.swift

@@ -63,7 +63,7 @@ open class ClientCallServerStreamingBase<InputType: Message, OutputType: Message
         returnError = error
         sem.signal()
       }
-      _ = sem.wait(timeout: DispatchTime.distantFuture)
+      _ = sem.wait()
     }
     if let returnError = returnError {
       throw returnError

+ 1 - 1
Sources/gRPC/GenCodeSupport/ClientCallUnary.swift

@@ -35,7 +35,7 @@ open class ClientCallUnaryBase<InputType: Message, OutputType: Message>: ClientC
       returnCallResult = callResult
       sem.signal()
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     if let returnResponse = returnResponse {
       return returnResponse
     } else {

+ 2 - 2
Sources/gRPC/GenCodeSupport/ServerSessionBidirectionalStreaming.swift

@@ -42,7 +42,7 @@ open class ServerSessionBidirectionalStreamingBase<InputType: Message, OutputTyp
       }
       sem.signal()
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     if let requestMessage = requestMessage {
       return requestMessage
     } else {
@@ -59,7 +59,7 @@ open class ServerSessionBidirectionalStreamingBase<InputType: Message, OutputTyp
     try handler.sendStatus(statusCode: statusCode,
                            statusMessage: statusMessage,
                            trailingMetadata: trailingMetadata) { _ in sem.signal() }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
   }
 
   public func run(queue: DispatchQueue) throws {

+ 1 - 1
Sources/gRPC/GenCodeSupport/ServerSessionClientStreaming.swift

@@ -38,7 +38,7 @@ open class ServerSessionClientStreamingBase<InputType: Message, OutputType: Mess
       }
       sem.signal()
     }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
     if requestMessage == nil {
       throw ServerError.endOfStream
     }

+ 3 - 3
Tests/gRPCTests/GRPCTests.swift

@@ -118,7 +118,7 @@ func runTest(useSSL: Bool) {
   server.stop()
 
   // wait until the server has shut down
-  _ = serverRunningSemaphore.wait(timeout: DispatchTime.distantFuture)
+  _ = serverRunningSemaphore.wait()
 }
 
 func verify_metadata(_ metadata: Metadata, expected: [String: String], file: StaticString = #file, line: UInt = #line) {
@@ -175,7 +175,7 @@ func runClient(useSSL: Bool) throws {
       sem.signal()
     }
     // wait for the call to complete
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
+    _ = sem.wait()
   }
 }
 
@@ -209,5 +209,5 @@ func runServer(server: Server) throws {
     sem.signal()
   }
   // wait for the server to exit
-  _ = sem.wait(timeout: DispatchTime.distantFuture)
+  _ = sem.wait()
 }