Skip to content

Commit 5476123

Browse files
committed
[stdlib] Add Clock.Duration as an associated type requirement
As [discussed on the forum][forum], we'll likely want to use `Duration` as the primary associated type on `protocol Clock`; however, that protocol currently only has `Instant`. [forum]: https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/39 To support declaring it as the primary associated type, `protocol Clock` needs to have `Duration` as an associated type requirement: ``` @available(SwiftStdlib 5.7, *) public protocol Clock: Sendable { associatedtype Duration: DurationProtocol associatedtype Instant: InstantProtocol where Instant.Duration == Duration var now: Instant { get } var minimumResolution: Instant.Duration { get } func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws } ``` This setup is reminiscent of `Sequence.Element` vs. `Sequence.Iterator.Element`. SE-0329 has not yet shipped in an ABI stable release, so we still have the opportunity to address this. rdar://91591545 (cherry picked from commit 0aadfb0)
1 parent e006a0d commit 5476123

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/Concurrency/Clock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import Swift
3232
/// `SuspendingClock`.
3333
@available(SwiftStdlib 5.7, *)
3434
public protocol Clock: Sendable {
35-
associatedtype Instant: InstantProtocol
35+
associatedtype Duration: DurationProtocol
36+
associatedtype Instant: InstantProtocol where Instant.Duration == Duration
3637

3738
var now: Instant { get }
3839
var minimumResolution: Instant.Duration { get }

0 commit comments

Comments
 (0)