Last active
November 13, 2020 20:48
-
-
Save mbrandonw/cb4848c9896680af6d250d9ae5f15cdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Effect { | |
func cancellable<Id: Hashable>(id: Id) -> Effect<Output> { | |
return Deferred { () -> PassthroughSubject<Output, Failure> in | |
cancellables[id]?.cancel() | |
let subject = PassthroughSubject<Output, Failure>() | |
cancellables[id] = self.subscribe(subject) | |
return subject | |
} | |
.eraseToEffect() | |
} | |
} | |
extension Effect where Output == Never { | |
static func cancel<Id: Hashable>(id: Id) -> Effect { | |
.fireAndForget { | |
cancellables[id]?.cancel() | |
cancellables[id] = nil | |
} | |
} | |
} | |
private var cancellables: [AnyHashable: AnyCancellable] = [:] |
Nah that's not necessary, it should be removed. Good catch!
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mbrandonw thanks for sharing!
Quick question: is there a specific reason
where Output == Never
?