Skip to content

Commit e9ed546

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

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 19 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

0 commit comments

Comments
 (0)