@@ -6,6 +6,42 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
6
6
Swift 5.5
7
7
---------
8
8
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
+
9
45
* [ SE-0316] [ ] :
10
46
11
47
A type can be defined as a global actor. Global actors extend the notion
@@ -8562,6 +8598,7 @@ Swift 1.0
8562
8598
[SE- 0300 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
8563
8599
[SE- 0306 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
8564
8600
[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>
8565
8602
[SE- 0313 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8566
8603
[SE- 0316 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
8567
8604
0 commit comments