Skip to content

Commit

Permalink
Fix access control
Browse files Browse the repository at this point in the history
A few APIs were `public` when they shouldn't be. They aren't primary
APIs, and it is unlikely that folks rely on them. So though this is a
breaking change, it shouldn't affect folks, and there is an alternative
API they can rely on instead.
  • Loading branch information
stephencelis committed Jan 5, 2024
1 parent 2365f6f commit d31f5d4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/Clocks/AnyClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@
self._sleep = { try await clock.sleep(until: start.advanced(by: $0.offset), tolerance: $1) }
}

public var minimumResolution: Instant.Duration {
public var minimumResolution: Duration {
self._minimumResolution()
}

public var now: Instant {
self._now()
}

public func sleep(until deadline: Instant, tolerance: Instant.Duration? = nil) async throws {
public func sleep(until deadline: Instant, tolerance: Duration? = nil) async throws {
try await self._sleep(deadline, tolerance)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Clocks/ImmediateClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
Duration: Hashable
{
public struct Instant: InstantProtocol {
public let offset: Duration
fileprivate let offset: Duration

public init(offset: Duration = .zero) {
self.offset = offset
}
Expand All @@ -133,15 +133,15 @@
}
}

public var now: Instant
public var minimumResolution: Duration = .zero
public private(set) var now: Instant
public private(set) var minimumResolution: Duration = .zero
private let lock = NSLock()

public init(now: Instant = .init()) {
self.now = now
}

public func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws {
public func sleep(until deadline: Instant, tolerance: Duration?) async throws {
try Task.checkCancellation()
self.lock.sync { self.now = deadline }
await Task.megaYield()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Clocks/TestClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
public final class TestClock<Duration: DurationProtocol & Hashable>: Clock, @unchecked Sendable {
public struct Instant: InstantProtocol {
public let offset: Duration
fileprivate let offset: Duration

public init(offset: Duration = .zero) {
self.offset = offset
Expand Down
3 changes: 2 additions & 1 deletion Tests/ClocksTests/ImmediateClockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ final class ImmediateClockTests: XCTestCase {

func testNow() async throws {
let clock = ImmediateClock()
let start = clock.now
try await clock.sleep(for: .seconds(5))
XCTAssertEqual(clock.now.offset, .seconds(5))
XCTAssertEqual(start.advanced(by: .seconds(5)), clock.now)
}

func testCooperativeCancellation() async throws {
Expand Down
3 changes: 2 additions & 1 deletion Tests/ClocksTests/TestClocksTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ final class TestClockTests: XCTestCase, @unchecked Sendable {
let task = Task {
try await self.clock.sleep(for: .seconds(5))
}
let start = self.clock.now
await self.clock.advance(by: .seconds(5))
XCTAssertEqual(self.clock.now.offset, .seconds(5))
XCTAssertEqual(start.advanced(by: .seconds(5)), self.clock.now)
try await task.value
}

Expand Down

0 comments on commit d31f5d4

Please sign in to comment.