Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ jobs:
strategy:
matrix:
xcode:
- "26.2"
- "26.5"
steps:
- uses: actions/checkout@v5
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Print Swift version
run: swift --version
- name: Install Simulator Runtimes
if: matrix.xcode != '26.2'
uses: nick-fields/retry@v3
with:
timeout_minutes: 15
max_attempts: 3
command: xcodebuild -downloadAllPlatforms
- name: Run ${{ matrix.config }} tests
run: CONFIG=${{ matrix.config }} make test-all

Expand All @@ -36,6 +44,7 @@ jobs:
matrix:
config: ["debug", "release"]
swift:
- "6.0"
- "6.3"
container: swift:${{ matrix.swift }}
steps:
Expand Down
7 changes: 3 additions & 4 deletions Sources/Clocks/ImmediateClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,17 @@
}
}

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

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

public func sleep(until deadline: Instant, tolerance: Duration?) async throws {
public func sleep(until deadline: Instant, tolerance: Duration?) throws {
try Task.checkCancellation()
self.lock.sync { self.now = deadline }
await Task.megaYield()
}
}

Expand Down
34 changes: 34 additions & 0 deletions Sources/Clocks/NonsendingClock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#if compiler(>=6.2)
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
public protocol NonsendingClock<Duration>: Clock {
nonisolated(nonsending)
func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension NonsendingClock {
nonisolated(nonsending)
public func sleep(for duration: Duration, tolerance: Instant.Duration? = nil) async throws
{
try await sleep(until: now.advanced(by: duration), tolerance: tolerance)
}
}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension AnyClock: NonsendingClock {}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension ContinuousClock: NonsendingClock {}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension ImmediateClock: NonsendingClock {}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension SuspendingClock: NonsendingClock {}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension TestClock: NonsendingClock {}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension UnimplementedClock: NonsendingClock {}
#endif
Loading