Преглед изворни кода

Fix Task sleep backport (#1719)

Motivation:

The `Task.sleep(for:tolerance:clock:)` backport was added behind a
`swift(<5.8)` guard, this should be 5.9. Moreover, the backport just
dropped the clock type rather than using the `Task.sleep(until:)` API.

Modifications:

- Raise Swift version
- Use `Task.sleep(until:)` so the correct clock type is used.

Result:

Fewer build failures
George Barnett пре 2 година
родитељ
комит
0acdb9b46d
1 измењених фајлова са 7 додато и 3 уклоњено
  1. 7 3
      Sources/GRPCCore/Internal/Task+SleepBackport.swift

+ 7 - 3
Sources/GRPCCore/Internal/Task+SleepBackport.swift

@@ -14,12 +14,16 @@
  * limitations under the License.
  */
 
-#if swift(<5.8)
+#if swift(<5.9)
 @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
 extension Task where Success == Never, Failure == Never {
   @inlinable
-  static func sleep(for duration: Duration, clock: ContinuousClock) async throws {
-    try await Self.sleep(for: duration)
+  static func sleep<C: Clock>(
+    for duration: C.Instant.Duration,
+    tolerance: C.Instant.Duration? = nil,
+    clock: C = ContinuousClock()
+  ) async throws {
+    try await clock.sleep(until: clock.now.advanced(by: duration), tolerance: tolerance)
   }
 }
 #endif