From b186745f7593e25400397dbda006908199c27333 Mon Sep 17 00:00:00 2001 From: dankinsoid <30962149+dankinsoid@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:48:49 +0300 Subject: [PATCH] 1.5.4 --- README.md | 2 +- Sources/SwiftAPIClient/Modifiers/TimeoutModifiers.swift | 2 +- Sources/SwiftAPIClient/Types/TimeoutError.swift | 4 ++-- Tests/SwiftAPIClientTests/UtilsTests/WithTimeoutTests.swift | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 58aa3d8..dafa745 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,7 @@ import PackageDescription let package = Package( name: "SomeProject", dependencies: [ - .package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.5.3") + .package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "1.5.4") ], targets: [ .target( diff --git a/Sources/SwiftAPIClient/Modifiers/TimeoutModifiers.swift b/Sources/SwiftAPIClient/Modifiers/TimeoutModifiers.swift index cc1fb90..3d78b6e 100644 --- a/Sources/SwiftAPIClient/Modifiers/TimeoutModifiers.swift +++ b/Sources/SwiftAPIClient/Modifiers/TimeoutModifiers.swift @@ -76,7 +76,7 @@ public extension APIClient { self.timeout( timeout, seconds: { Double($0.components.seconds) + Double($0.components.attoseconds) * pow(10.0, -18.0) }, - sleep: { try await clock.sleep(for: $0, tolerance: tolerance) }, + sleep: { try await clock.sleep(until: clock.now.advanced(by: $0), tolerance: tolerance) }, fileID: fileID, line: line ) diff --git a/Sources/SwiftAPIClient/Types/TimeoutError.swift b/Sources/SwiftAPIClient/Types/TimeoutError.swift index c17db9c..6ef4f4f 100644 --- a/Sources/SwiftAPIClient/Types/TimeoutError.swift +++ b/Sources/SwiftAPIClient/Types/TimeoutError.swift @@ -43,8 +43,8 @@ public func withTimeout( ) async throws -> T where C.Duration == Duration { try await withTimeout( timeout, - seconds: { Double($0.components.seconds) + Double($0.components.attoseconds) * pow(10, -18) }, - sleep: { try await clock.sleep(for: $0, tolerance: tolerance) }, + seconds: { Double($0.components.seconds) + (Double($0.components.attoseconds) * pow(10, -18)) }, + sleep: { try await clock.sleep(until: clock.now.advanced(by: $0), tolerance: tolerance) }, fileID: fileID, line: line, operation: operation diff --git a/Tests/SwiftAPIClientTests/UtilsTests/WithTimeoutTests.swift b/Tests/SwiftAPIClientTests/UtilsTests/WithTimeoutTests.swift index 5762e31..e95ad0d 100644 --- a/Tests/SwiftAPIClientTests/UtilsTests/WithTimeoutTests.swift +++ b/Tests/SwiftAPIClientTests/UtilsTests/WithTimeoutTests.swift @@ -22,7 +22,7 @@ class WithTimeoutTests: XCTestCase { func test_withTimeout_timeout() async { do { _ = try await withTimeout(.nanoseconds(2)) { - try await Task.sleep(for: .milliseconds(4)) + try await Task.sleep(until: .now.advanced(by: .milliseconds(4))) return 42 } XCTFail("Expected timeout error") @@ -33,7 +33,7 @@ class WithTimeoutTests: XCTestCase { func test_withTimeout_success() async throws { _ = try await withTimeout(.milliseconds(4)) { - try await Task.sleep(for: .nanoseconds(2)) + try await Task.sleep(until: .now.advanced(by: .nanoseconds(2))) return 42 } }