Skip to content

Commit 1d3eb30

Browse files
authored
Merge pull request #38282 from apple/ktoso-patch-3
2 parents bee879c + 6908287 commit 1d3eb30

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.5
77
---------
88

9+
* [SE-0311][]:
10+
11+
Task local values can be defined using the new `@TaskLocal` property wrapper.
12+
Such values are carried implicitly by the task in which the binding was made,
13+
as well as any child-tasks, and unstructured task created from the tasks context.
14+
15+
```swift
16+
struct TraceID {
17+
@TaskLocal
18+
static var current: TraceID?
19+
}
20+
21+
func printTraceID() {
22+
if let traceID = TraceID.current {
23+
print("\(traceID)")
24+
} else {
25+
print("nil")
26+
}
27+
}
28+
29+
func run() async {
30+
printTraceID() // prints: nil
31+
TraceID.$current.withValue("1234-5678") {
32+
printTraceID() // prints: 1234-5678
33+
inner() // prints: 1234-5678
34+
}
35+
printTraceID() // prints: nil
36+
}
37+
38+
func inner() {
39+
// if called from a context in which the task-local value
40+
// was bound, it will print it (or 'nil' otherwise)
41+
printTraceID()
42+
}
43+
```
44+
945
* [SE-0316][]:
1046

1147
A type can be defined as a global actor. Global actors extend the notion
@@ -8562,6 +8598,7 @@ Swift 1.0
85628598
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
85638599
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
85648600
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
8601+
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
85658602
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
85668603
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
85678604

0 commit comments

Comments
 (0)