Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions Sources/Helpers/SupabaseLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,46 @@ extension SupabaseLogger {
}
}

@inlinable
@discardableResult
@_unsafeInheritExecutor
package func trace<R>(
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<R: Sendable>(
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<R: Sendable>(
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
57 changes: 39 additions & 18 deletions Sources/Helpers/TaskLocalHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,43 @@

import Foundation

extension TaskLocal where Value == JSONObject {
@inlinable
@discardableResult
@_unsafeInheritExecutor
package func withValue<R>(
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<R>(
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<R>(
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
Loading