@@ -89,48 +89,22 @@ extension Task {
8989 ///
9090 /// - Parameters:
9191 /// - keyPath: key path to the `TaskLocalKey` to be used for lookup
92- /// - value:
93- /// - body:
92+ /// - value: value to bind the task local to for the scope of `operation`
93+ /// - operation: the operation to run with the task local value bound
9494 /// - Returns: the value returned by the `body` function.
9595 public static func withLocal< Key, BodyResult> (
9696 _ keyPath: KeyPath < TaskLocalValues , Key > ,
9797 boundTo value: Key . Value ,
98- body : @escaping ( ) async -> BodyResult
99- ) async -> BodyResult where Key: TaskLocalKey {
98+ operation : ( ) async throws -> BodyResult
99+ ) async rethrows -> BodyResult where Key: TaskLocalKey {
100100 let task = Builtin . getCurrentAsyncTask ( )
101101
102102 _taskLocalValuePush ( task, keyType: Key . self, value: value)
103-
104- defer {
105- _taskLocalValuePop ( task)
106- }
103+ defer { _taskLocalValuePop ( task) }
107104
108- return await body ( )
105+ return try await body ( )
109106 }
110107
111- /// Bind the task local key to the given value for the scope of the `body` function.
112- /// Any child tasks spawned within this scope will inherit the binding.
113- ///
114- /// - Parameters:
115- /// - key:
116- /// - value:
117- /// - body:
118- /// - Returns: the value returned by the `body` function, or throws.
119- public static func withLocal< Key, BodyResult> (
120- _ keyPath: KeyPath < TaskLocalValues , Key > ,
121- boundTo value: Key . Value ,
122- body: @escaping ( ) async throws -> BodyResult
123- ) async throws -> BodyResult where Key: TaskLocalKey {
124- let task = Builtin . getCurrentAsyncTask ( )
125-
126- _taskLocalValuePush ( task, keyType: Key . self, value: value)
127-
128- defer {
129- _taskLocalValuePop ( task)
130- }
131-
132- return try ! await body ( )
133- }
134108}
135109
136110// ==== ------------------------------------------------------------------------
0 commit comments