Skip to content

Commit ee13d74

Browse files
stephencelismluisbrown
authored andcommitted
Add more permissive fire-and-forget effect (#427)
* Add more permissive fire-and-forget effect * Update Effect.swift * Update Effect.swift
1 parent 81a74d7 commit ee13d74

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
@@ -126,6 +126,24 @@ extension Effect {
126126
self.map(Result<Value, Error>.success)
127127
.flatMapError { Effect<Result<Value, Error>, Never>(value: Result.failure($0)) }
128128
}
129+
130+
/// Turns any publisher into an `Effect` for any output and failure type by ignoring all output
131+
/// and any failure.
132+
///
133+
/// This is useful for times you want to fire off an effect but don't want to feed any data back
134+
/// into the system.
135+
///
136+
/// case .buttonTapped:
137+
/// return analyticsClient.track("Button Tapped")
138+
/// .fireAndForget()
139+
///
140+
/// - Returns: An effect that never produces output or errors.
141+
public func fireAndForget<NewValue, NewError>() -> Effect<NewValue, NewError> {
142+
self.flatMapError { _ in .empty }
143+
.flatMap(.latest) { _ in
144+
.empty
145+
}
146+
}
129147
}
130148

131149
extension Effect where Value == Never {

0 commit comments

Comments
 (0)