@@ -17,7 +17,9 @@ import Swift
17
17
// Macros are disabled when Swift is built without swift-syntax.
18
18
#if $Macros && hasAttribute(attached)
19
19
20
- // TODO: docs
20
+ /// Macro that introduces a ``TaskLocal-class`` binding.
21
+ ///
22
+ /// - SeeAlso: ``TaskLocal-class``
21
23
@available ( SwiftStdlib 5 . 1 , * )
22
24
@attached ( accessor)
23
25
@attached ( peer, names: prefixed ( `$`) )
@@ -26,22 +28,25 @@ public macro TaskLocal() =
26
28
27
29
#endif
28
30
29
- /// Wrapper that defines a task-local value key.
31
+ /// Wrapper type that defines a task-local value key.
30
32
///
31
33
/// A task-local value is a value that can be bound and read in the context of a
32
- /// `Task`. It is implicitly carried with the task, and is accessible by any
33
- /// child tasks the task creates (such as TaskGroup or `async let` created tasks).
34
+ /// `` Task` `. It is implicitly carried with the task, and is accessible by any
35
+ /// child tasks it creates (such as TaskGroup or `async let` created tasks).
34
36
///
35
37
/// ### Task-local declarations
36
38
///
37
- /// Task locals must be declared as static properties (or global properties,
38
- /// once property wrappers support these), like this:
39
+ /// Task locals must be declared as static properties or global properties, like this:
39
40
///
40
41
/// enum Example {
41
42
/// @TaskLocal
42
43
/// static let traceID: TraceID?
43
44
/// }
44
45
///
46
+ /// // Global task local properties are supported since Swift 6.0:
47
+ /// @TaskLocal
48
+ /// var contextualNumber: Int = 12
49
+ ///
45
50
/// ### Default values
46
51
/// Reading a task local value when no value was bound to it results in returning
47
52
/// its default value. For a task local declared as optional (such as e.g. `TraceID?`),
@@ -150,6 +155,8 @@ public macro TaskLocal() =
150
155
/// read() // traceID: nil
151
156
/// }
152
157
/// }
158
+ ///
159
+ /// - SeeAlso: ``TaskLocal-macro``
153
160
@available ( SwiftStdlib 5 . 1 , * )
154
161
public final class TaskLocal < Value: Sendable > : Sendable , CustomStringConvertible {
155
162
let defaultValue : Value
0 commit comments