Skip to content

Commit 7cee1cc

Browse files
committed
Cancel in flight effects inline instead of returning concatenated effect (#976)
1 parent 188cb7a commit 7cee1cc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Sources/ComposableArchitecture/Effects/Cancellation.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ extension Effect {
3939
/// canceled before starting this new one.
4040
/// - Returns: A new effect that is capable of being canceled by an identifier.
4141
public func cancellable(id: AnyHashable, cancelInFlight: Bool = false) -> Effect {
42-
let effect = Effect.deferred { () -> SignalProducer<Value, Error> in
42+
Effect.deferred { () -> SignalProducer<Value, Error> in
4343
cancellablesLock.lock()
4444
defer { cancellablesLock.unlock() }
4545

46+
if cancelInFlight {
47+
cancellationCancellables[id]?.forEach { $0.dispose() }
48+
}
49+
4650
let subject = Signal<Value, Error>.pipe()
4751

4852
var values: [Value] = []
@@ -82,8 +86,6 @@ extension Effect {
8286
disposed: cancellationDisposable.dispose
8387
)
8488
}
85-
86-
return cancelInFlight ? .concatenate(.cancel(id: id), effect) : effect
8789
}
8890

8991
/// An effect that will cancel any currently in-flight effect with the given identifier.

0 commit comments

Comments
 (0)