Skip to content

Commit ea146ac

Browse files
authored
[Concurrency,docs] Update task local docs to use latest structured concurrency APIs (#38499)
1 parent ab594dd commit ea146ac

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ import Swift
6464
/// are created within that scope.
6565
///
6666
/// Detached tasks do not inherit task-local values, however tasks created using
67-
/// the `async {}` operation do inherit task-locals by copying them to the new
68-
/// asynchronous task, even though it is an un-structured task.
67+
/// the `Task { ... }` initializer do inherit task-locals by copying them to the
68+
/// new asynchronous task, even though it is an un-structured task.
6969
///
7070
/// ### Examples
7171
///
@@ -78,12 +78,12 @@ import Swift
7878
/// print("traceID: \(traceID)") // traceID: 1234
7979
/// call() // traceID: 1234
8080
///
81-
/// asyncDetached { // detached tasks do not inherit task-local values
82-
/// call() // traceID: nil
81+
/// Task { // unstructured tasks do inherit task locals by copying
82+
/// call() // traceID: 1234
8383
/// }
8484
///
85-
/// async { // async tasks do inherit task locals by copying
86-
/// call() // traceID: 1234
85+
/// Task.detached { // detached tasks do not inherit task-local values
86+
/// call() // traceID: nil
8787
/// }
8888
/// }
8989
///
@@ -147,15 +147,16 @@ public final class TaskLocal<Value>: UnsafeSendable, CustomStringConvertible {
147147
return try await operation()
148148
}
149149

150-
/// Binds the task-local to the specific value for the duration of the synchronous operation.
150+
/// Binds the task-local to the specific value for the duration of the
151+
/// synchronous operation.
151152
///
152153
/// The value is available throughout the execution of the operation closure,
153154
/// including any `get` operations performed by child-tasks created during the
154155
/// execution of the operation closure.
155156
///
156157
/// If the same task-local is bound multiple times, be it in the same task, or
157-
/// in specific child tasks, the more specific (i.e. "deeper") binding is
158-
/// returned when the value is read.
158+
/// in specific child tasks, the "more specific" binding is returned when the
159+
/// value is read.
159160
///
160161
/// If the value is a reference type, it will be retained for the duration of
161162
/// the operation closure.
@@ -194,7 +195,7 @@ public final class TaskLocal<Value>: UnsafeSendable, CustomStringConvertible {
194195
storage storageKeyPath: ReferenceWritableKeyPath<Never, TaskLocal<Value>>
195196
) -> Value {
196197
get {
197-
fatalError()
198+
fatalError("Will never be executed, since enclosing instance is Never")
198199
}
199200
}
200201

0 commit comments

Comments
 (0)