Last active
October 21, 2019 15:16
-
-
Save nalexn/10434d48d421a0f62ffecc5c36c3e57c to your computer and use it in GitHub Desktop.
Article_001 https://nalexn.github.io/cancelbag-for-combine/
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
class ValueConsumer { | |
private var subscriptions = Set<AnyCancellable>() | |
private let mySubject = CurrentValueSubject<Int, Never>(0) | |
private var myVar: Int = 0 | |
func consumeValues(publisher1, ...) { | |
subscriptions.collect { | |
publisher1 | |
.sink { print("New value: \($0)") } | |
mySubject | |
.subscribe(publisher2) | |
publisher3 | |
.assign(to: \.myVar, on: self) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment