Skip to content

Commit 63f0589

Browse files
committed
Add release notes for SE-0329: Clock, Instant, and Duration
1 parent 09f397d commit 63f0589

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0329][]:
9+
New types representing time and clocks were introduced. This includes a protocol `Clock` defining clocks which allow for defining a concept of now and a way to wake up after a given instant. Additionally a new protocol `InstantProtocol` for defining instants in time was added. Furthermore a new protocol `DurationProtocol` was added to define an elapsed duration between two given `InstantProtocol` types. Most commonly the `Clock` types for general use are the `SuspendingClock` and `ContinuousClock` which represent the most fundamental clocks for the system. The `SuspendingClock` type does not progress while the machine is suspended whereas the `ContinuousClock` progresses no matter the state of the machine.
10+
11+
```swift
12+
func delayedHello() async throws {
13+
try await Task.sleep(until: .now + .milliseconds(123), clock: .continuous)
14+
print("hello delayed world")
15+
}
16+
```
17+
18+
`Clock` also has methods to measure the elapsed duration of the execution of work. In the case of the `SuspendingClock` and `ContinuousClock` this measures with high resolution and is suitable for benchmarks.
19+
20+
```swift
21+
let clock = ContinuousClock()
22+
let elapsed = clock.measure {
23+
someLongRunningWork()
24+
}
25+
```
26+
827
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
928

1029
```swift
@@ -9270,6 +9289,7 @@ Swift 1.0
92709289
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
92719290
[SE-0349]: <https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
92729291
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
9292+
[SE-0329]: <https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md>
92739293

92749294
[SR-75]: <https://bugs.swift.org/browse/SR-75>
92759295
[SR-106]: <https://bugs.swift.org/browse/SR-106>

0 commit comments

Comments
 (0)