diff --git a/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved index f5db38ed..02823ff1 100644 --- a/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,12 +1,13 @@ { + "originHash" : "2ca7dd5573d7cd82bd1a861bfa2cbb6254b949f9d0193fc563644db073efed83", "pins" : [ { "identity" : "combine-schedulers", "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/combine-schedulers", "state" : { - "revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13", - "version" : "1.0.2" + "revision" : "dcccb979a2183b8df3334237e3dc1ae2b4116a86", + "version" : "1.2.0" } }, { @@ -14,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-clocks", "state" : { - "revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53", - "version" : "1.0.5" + "revision" : "72d749bf341b78851203066ab421869b783ec42a", + "version" : "1.1.0" } }, { @@ -23,8 +24,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-concurrency-extras", "state" : { - "revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71", - "version" : "1.1.0" + "revision" : "a90e2e40a7a840a853dd29e57cbef5dbb72c9d5b", + "version" : "1.4.0" + } + }, + { + "identity" : "swift-custom-dump", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-custom-dump", + "state" : { + "revision" : "a8cd6c976f335ed361dcecddb0dc39ebda51bc3e", + "version" : "1.6.1" } }, { @@ -32,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-docc-plugin", "state" : { - "revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680", - "version" : "1.4.2" + "revision" : "647c708be89f834fa6a6d4945442793a77ddf5b6", + "version" : "1.5.0" } }, { @@ -50,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-macro-testing", "state" : { - "revision" : "20c1a8f3b624fb5d1503eadcaa84743050c350f4", - "version" : "0.5.2" + "revision" : "2e494c632d510715c96a694ff25e2a8d4ac3f64b", + "version" : "0.6.5" } }, { @@ -59,8 +69,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { - "revision" : "6d932a79e7173b275b96c600c86c603cf84f153c", - "version" : "1.17.4" + "revision" : "ad5e3190cc63dc288f28546f9c6827efc1e9d495", + "version" : "1.19.2" } }, { @@ -68,8 +78,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax", "state" : { - "revision" : "515f79b522918f83483068d99c68daeb5116342d", - "version" : "600.0.0-prerelease-2024-09-04" + "revision" : "79e4b74a295b6eb74a8b585e3a39d29e70c1dbd1", + "version" : "603.0.2" } }, { @@ -77,10 +87,10 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe", - "version" : "1.4.0" + "revision" : "401bf70d95bfe8db2a1dc619f9e175a85c089321", + "version" : "1.10.1" } } ], - "version" : 2 + "version" : 3 } diff --git a/Package.resolved b/Package.resolved index cf926bb1..dc363640 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "f171a17395c71a4cc28a00fe9f5d0dac8112abe5c378b4cbdc65a193bb83fb82", + "originHash" : "308e03b9090ee5c6d7965fe88ba3ff454b02b7e4d9f34bcc99f18bc08a32f5d5", "pins" : [ { "identity" : "combine-schedulers", @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-clocks", "state" : { - "revision" : "cc46202b53476d64e824e0b6612da09d84ffde8e", - "version" : "1.0.6" + "revision" : "72d749bf341b78851203066ab421869b783ec42a", + "version" : "1.1.0" } }, { @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-concurrency-extras", "state" : { - "revision" : "5a3825302b1a0d744183200915a47b508c828e6f", - "version" : "1.3.2" + "revision" : "a90e2e40a7a840a853dd29e57cbef5dbb72c9d5b", + "version" : "1.4.0" } }, { @@ -33,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-custom-dump", "state" : { - "revision" : "06c57924455064182d6b217f06ebc05d00cb2990", - "version" : "1.5.0" + "revision" : "a8cd6c976f335ed361dcecddb0dc39ebda51bc3e", + "version" : "1.6.1" } }, { @@ -78,8 +78,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax", "state" : { - "revision" : "9de99a78f099e59caf2b2beec65a4c45d54b2081", - "version" : "603.0.1" + "revision" : "79e4b74a295b6eb74a8b585e3a39d29e70c1dbd1", + "version" : "603.0.2" } }, { @@ -87,8 +87,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "cb281f343fd953280336dcbd3822cdf47c182f5b", - "version" : "1.10.0" + "revision" : "401bf70d95bfe8db2a1dc619f9e175a85c089321", + "version" : "1.10.1" } } ], diff --git a/Package.swift b/Package.swift index 1429d427..216c7275 100644 --- a/Package.swift +++ b/Package.swift @@ -38,7 +38,7 @@ let package = Package( .package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.2"), .package(url: "https://github.com/pointfreeco/swift-clocks", from: "1.0.4"), .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"), - .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.4.0"), + .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"), .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"605.0.0"), ], targets: [ diff --git a/Sources/Dependencies/DependencyValues/FireAndForget.swift b/Sources/Dependencies/DependencyValues/FireAndForget.swift index 02cf2f3e..bf298e41 100644 --- a/Sources/Dependencies/DependencyValues/FireAndForget.swift +++ b/Sources/Dependencies/DependencyValues/FireAndForget.swift @@ -1,3 +1,5 @@ +import IssueReporting + extension DependencyValues { /// A dependency for firing off an unstructured task. /// @@ -54,21 +56,36 @@ extension DependencyValues { /// See ``DependencyValues/fireAndForget`` for more information. public struct FireAndForget: Sendable { public let operation: - @Sendable (TaskPriority?, @Sendable @escaping () async throws -> Void) async -> Void + @Sendable (String?, TaskPriority?, @Sendable @escaping () async throws -> Void) async -> Void public func callAsFunction( + name: String? = nil, priority: TaskPriority? = nil, @_inheritActorContext _ operation: @Sendable @escaping () async throws -> Void ) async { - await self.operation(priority) { try await operation() } + await self.operation(name, priority) { try await operation() } } } private enum FireAndForgetKey: DependencyKey { - public static let liveValue = FireAndForget { priority, operation in - _ = Task(priority: priority) { try await operation() } + public static let liveValue = FireAndForget { name, priority, operation in + #if compiler(>=6.2) + _ = Task(name: name, priority: priority) { try await operation() } + #else + _ = Task(priority: priority) { try await operation() } + #endif } - public static let testValue = FireAndForget { priority, operation in - await Task(priority: priority) { try? await operation() }.value + public static let testValue = FireAndForget { name, priority, operation in + #if compiler(>=6.2) + await Task(name: name, priority: priority) { + await withErrorReporting { try await operation() } + } + .value + #else + await Task(priority: priority) { + await withErrorReporting { try await operation() } + } + .value + #endif } } diff --git a/Tests/DependenciesTests/FireAndForgetTests.swift b/Tests/DependenciesTests/FireAndForgetTests.swift index df23f73a..c2069a2a 100644 --- a/Tests/DependenciesTests/FireAndForgetTests.swift +++ b/Tests/DependenciesTests/FireAndForgetTests.swift @@ -1,5 +1,6 @@ import ConcurrencyExtras import Dependencies +import Testing import XCTest final class FireAndForgetTests: XCTestCase { @@ -83,3 +84,15 @@ final class FireAndForgetTests: XCTestCase { } #endif } + +@Test func failure() async { + @Dependency(\.fireAndForget) var fireAndForget + struct Failure: Error {} + await withKnownIssue { + await fireAndForget { + throw Failure() + } + } matching: { + $0.description.contains("Failure()") + } +}