diff --git a/Sources/Helpers/SupabaseLogger.swift b/Sources/Helpers/SupabaseLogger.swift index 1b0077f03..0352a334e 100644 --- a/Sources/Helpers/SupabaseLogger.swift +++ b/Sources/Helpers/SupabaseLogger.swift @@ -171,23 +171,46 @@ extension SupabaseLogger { } } -@inlinable -@discardableResult -@_unsafeInheritExecutor -package func trace( - using logger: (any SupabaseLogger)?, - @_inheritActorContext _ operation: @Sendable () async throws -> R, - fileID: StaticString = #fileID, - function: StaticString = #function, - line: UInt = #line -) async rethrows -> R { - logger?.debug("begin", fileID: fileID, function: function, line: line) - defer { logger?.debug("end", fileID: fileID, function: function, line: line) } - - do { - return try await operation() - } catch { - logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) - throw error +#if compiler(>=6.0) + @inlinable + @discardableResult + package func trace( + using logger: (any SupabaseLogger)?, + _ operation: () async throws -> R, + isolation _: isolated (any Actor)? = #isolation, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) async rethrows -> R { + logger?.debug("begin", fileID: fileID, function: function, line: line) + defer { logger?.debug("end", fileID: fileID, function: function, line: line) } + + do { + return try await operation() + } catch { + logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) + throw error + } } -} +#else + @_unsafeInheritExecutor + @inlinable + @discardableResult + package func trace( + using logger: (any SupabaseLogger)?, + _ operation: () async throws -> R, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) async rethrows -> R { + logger?.debug("begin", fileID: fileID, function: function, line: line) + defer { logger?.debug("end", fileID: fileID, function: function, line: line) } + + do { + return try await operation() + } catch { + logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) + throw error + } + } +#endif diff --git a/Sources/Helpers/TaskLocalHelpers.swift b/Sources/Helpers/TaskLocalHelpers.swift index 820570890..c2bc5592a 100644 --- a/Sources/Helpers/TaskLocalHelpers.swift +++ b/Sources/Helpers/TaskLocalHelpers.swift @@ -7,22 +7,43 @@ import Foundation -extension TaskLocal where Value == JSONObject { - @inlinable - @discardableResult - @_unsafeInheritExecutor - package func withValue( - merging valueDuringOperation: Value, - @_inheritActorContext operation: @Sendable () async throws -> R, - file: String = #fileID, - line: UInt = #line - ) async rethrows -> R { - let currentValue = wrappedValue - return try await withValue( - currentValue.merging(valueDuringOperation) { _, new in new }, - operation: operation, - file: file, - line: line - ) +#if compiler(>=6.0) + extension TaskLocal where Value == JSONObject { + @discardableResult + @inlinable package final func withValue( + merging valueDuringOperation: Value, + operation: () async throws -> R, + isolation: isolated (any Actor)? = #isolation, + file: String = #fileID, + line: UInt = #line + ) async rethrows -> R { + let currentValue = wrappedValue + return try await withValue( + currentValue.merging(valueDuringOperation) { _, new in new }, + operation: operation, + isolation: isolation, + file: file, + line: line + ) + } } -} +#else + extension TaskLocal where Value == JSONObject { + @_unsafeInheritExecutor + @discardableResult + @inlinable package final func withValue( + merging valueDuringOperation: Value, + operation: () async throws -> R, + file: String = #fileID, + line: UInt = #line + ) async rethrows -> R { + let currentValue = wrappedValue + return try await withValue( + currentValue.merging(valueDuringOperation) { _, new in new }, + operation: operation, + file: file, + line: line + ) + } + } +#endif