Skip to content

Commit 2e6d34e

Browse files
authored
Add more permissive fire-and-forget effect (#427)
* Add more permissive fire-and-forget effect * Update Effect.swift * Update Effect.swift
1 parent 9e50df4 commit 2e6d34e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,22 @@ extension Publisher {
333333
.catch { Just(.failure($0)) }
334334
.eraseToEffect()
335335
}
336+
337+
/// Turns any publisher into an `Effect` for any output and failure type by ignoring all output
338+
/// and any failure.
339+
///
340+
/// This is useful for times you want to fire off an effect but don't want to feed any data back
341+
/// into the system.
342+
///
343+
/// case .buttonTapped:
344+
/// return analyticsClient.track("Button Tapped")
345+
/// .fireAndForget()
346+
///
347+
/// - Returns: An effect that never produces output or errors.
348+
public func fireAndForget<NewOutput, NewFailure>() -> Effect<NewOutput, NewFailure> {
349+
return self
350+
.flatMap { _ in Empty() }
351+
.catch { _ in Empty() }
352+
.eraseToEffect()
353+
}
336354
}

0 commit comments

Comments
 (0)