diff --git a/Sources/tart/Utils.swift b/Sources/tart/Utils.swift index 1f2dc70..b7442e3 100644 --- a/Sources/tart/Utils.swift +++ b/Sources/tart/Utils.swift @@ -6,8 +6,11 @@ import Foundation struct ErrorReportingTask { let task: Task + // Inherit the caller's actor context, exactly as Task.init does. Without this, an + // operation written inside a @MainActor function runs on the cooperative pool + // rather than the main queue, trapping in callees that assert their queue. @discardableResult - init(_ context: String, operation: @escaping @Sendable () async throws -> Void) { + init(_ context: String, @_inheritActorContext operation: @escaping @Sendable () async throws -> Void) { task = Task { do { try await operation()