Skip to content

Commit 1a13dcd

Browse files
committed
[Concurrency] Improve new TaskLocal macro documentation
1 parent dbacc24 commit 1a13dcd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import Swift
1717
// Macros are disabled when Swift is built without swift-syntax.
1818
#if $Macros && hasAttribute(attached)
1919

20-
// TODO: docs
20+
/// Macro that introduces a ``TaskLocal-class`` binding.
21+
///
22+
/// - SeeAlso: ``TaskLocal-class``
2123
@available(SwiftStdlib 5.1, *)
2224
@attached(accessor)
2325
@attached(peer, names: prefixed(`$`))
@@ -26,22 +28,25 @@ public macro TaskLocal() =
2628

2729
#endif
2830

29-
/// Wrapper that defines a task-local value key.
31+
/// Wrapper type that defines a task-local value key.
3032
///
3133
/// 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).
3436
///
3537
/// ### Task-local declarations
3638
///
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:
3940
///
4041
/// enum Example {
4142
/// @TaskLocal
4243
/// static let traceID: TraceID?
4344
/// }
4445
///
46+
/// // Global task local properties are supported since Swift 6.0:
47+
/// @TaskLocal
48+
/// var contextualNumber: Int = 12
49+
///
4550
/// ### Default values
4651
/// Reading a task local value when no value was bound to it results in returning
4752
/// its default value. For a task local declared as optional (such as e.g. `TraceID?`),
@@ -150,6 +155,8 @@ public macro TaskLocal() =
150155
/// read() // traceID: nil
151156
/// }
152157
/// }
158+
///
159+
/// - SeeAlso: ``TaskLocal-macro``
153160
@available(SwiftStdlib 5.1, *)
154161
public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible {
155162
let defaultValue: Value

0 commit comments

Comments
 (0)