Skip to content

Commit c307541

Browse files
authored
Allow synchronous fireAndForget to throw (#1092)
1 parent 5fd7369 commit c307541

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,17 @@ public struct Effect<Output, Failure: Error>: Publisher {
242242
}
243243

244244
/// Creates an effect that executes some work in the real world that doesn't need to feed data
245-
/// back into the store.
245+
/// back into the store. If an error is thrown, the effect will complete and the error will be ignored.
246246
///
247247
/// - Parameter work: A closure encapsulating some work to execute in the real world.
248248
/// - Returns: An effect.
249-
public static func fireAndForget(_ work: @escaping () -> Void) -> Effect {
249+
public static func fireAndForget(_ work: @escaping () throws -> Void) -> Effect {
250250
// NB: Ideally we'd return a `Deferred` wrapping an `Empty(completeImmediately: true)`, but
251251
// due to a bug in iOS 13.2 that publisher will never complete. The bug was fixed in
252252
// iOS 13.3, but to remain compatible with iOS 13.2 and higher we need to do a little
253253
// trickery to make sure the deferred publisher completes.
254254
Deferred { () -> Publishers.CompactMap<Result<Output?, Failure>.Publisher, Output> in
255-
work()
255+
try? work()
256256
return Just<Output?>(nil)
257257
.setFailureType(to: Failure.self)
258258
.compactMap { $0 }

0 commit comments

Comments
 (0)