Instance Methodswift 6.0.1_Concurrency
withValue(_:operation:file:line:)
Binds the task-local to the specific value for the duration of the synchronous operation.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
@discardableResult func withValue<R>(_ valueDuringOperation: Value, operation: () throws -> R, file: String = #fileID, line: UInt = #line) rethrows -> R
The value is available throughout the execution of the operation closure, including any get
operations performed by child-tasks created during the execution of the operation closure.
If the same task-local is bound multiple times, be it in the same task, or in specific child tasks, the “more specific” binding is returned when the value is read.
If the value is a reference type, it will be retained for the duration of the operation closure.
Other members in extension
Type members
Instance members
var description: String
var projectedValue: TaskLocal<Value>
var wrappedValue: Value
func get(
) -> Value Gets the value currently bound to this task-local from the current task.
func withValue<R>(Value, operation: () async throws -> R, isolation: isolated (any Actor)?, file: String, line: UInt
) async rethrows -> R Binds the task-local to the specific value for the duration of the asynchronous operation.