Skip to content

Commit c43f904

Browse files
mbrandonwstephencelis
authored andcommitted
Ignore errors thrown in fireAndForget. (#1088)
* Ignore errors throw in fireAndForget. * Update Sources/ComposableArchitecture/Effects/Concurrency.swift Co-authored-by: Stephen Celis <[email protected]> * Update Sources/ComposableArchitecture/Effects/Concurrency.swift Co-authored-by: Stephen Celis <[email protected]>
1 parent feee88e commit c43f904

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Sources/ComposableArchitecture/Effects/Concurrency.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import ReactiveSwift
104104
}
105105

106106
/// Creates an effect that executes some work in the real world that doesn't need to feed data
107-
/// back into the store.
107+
/// back into the store. If an error is thrown, the effect will complete and the error will be ignored.
108108
///
109109
/// - Parameters:
110110
/// - priority: Priority of the underlying task. If `nil`, the priority will come from
@@ -113,9 +113,9 @@ import ReactiveSwift
113113
/// - Returns: An effect.
114114
public static func fireAndForget(
115115
priority: TaskPriority? = nil,
116-
_ work: @escaping @Sendable () async -> Void
116+
_ work: @escaping @Sendable () async throws -> Void
117117
) -> Effect {
118-
Effect<Void, Never>.task(priority: priority) { await work() }
118+
Effect<Void, Never>.task(priority: priority) { try? await work() }
119119
.fireAndForget()
120120
}
121121
}

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ final class EffectTests: XCTestCase {
249249
.start()
250250

251251
disposable.dispose()
252+
252253
_ = XCTWaiter.wait(for: [.init()], timeout: 1.1)
253254
}
254255

@@ -262,14 +263,15 @@ final class EffectTests: XCTestCase {
262263
return 42
263264
}
264265

265-
Effect<Int, Never >.task { await work() }
266-
.sink(
267-
receiveCompletion: { _ in XCTFail() },
268-
receiveValue: { _ in XCTFail() }
266+
let disposable = Effect<Int, Never >.task { await work() }
267+
.on(
268+
completed: { XCTFail() },
269+
value: { _ in XCTFail() }
269270
)
270-
.store(in: &self.cancellables)
271+
.start(on: QueueScheduler.main)
272+
.start()
271273

272-
self.cancellables = []
274+
disposable.dispose()
273275

274276
_ = XCTWaiter.wait(for: [.init()], timeout: 1.1)
275277
}

0 commit comments

Comments
 (0)