File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Sources/InstrumentationBaggage Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -236,5 +236,23 @@ extension Baggage {
236236 /// A `Baggage` automatically propagated through task-local storage. This API enables binding a top-level `Baggage` and passing it
237237 /// implicitly to any child tasks when using structured concurrency.
238238 @TaskLocal public static var current : Baggage ?
239+
240+ /// Convenience API to bind the task-local ``Baggage/current`` to the passed `value`, and execute the passed `operation`.
241+ ///
242+ /// To access the task-local value, use `Baggage.current`.
243+ ///
244+ /// SeeAlso: [Swift Task Locals](https://developer.apple.com/documentation/swift/tasklocal)
245+ func withValue< T> ( _ value: Baggage ? , operation: ( ) throws -> T ) rethrows -> T {
246+ try Baggage . $current. withValue ( value, operation: operation)
247+ }
248+
249+ /// Convenience API to bind the task-local ``Baggage/current`` to the passed `value`, and execute the passed `operation`.
250+ ///
251+ /// To access the task-local value, use `Baggage.current`.
252+ ///
253+ /// SeeAlso: [Swift Task Locals](https://developer.apple.com/documentation/swift/tasklocal)
254+ func withValue< T> ( _ value: Baggage ? , operation: ( ) async throws -> T ) async rethrows -> T {
255+ try await Baggage . $current. withValue ( value, operation: operation)
256+ }
239257}
240258#endif
You can’t perform that action at this time.
0 commit comments