Showing how `PassthroughSubject` drops value if there isn’t demand.
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
final class ManualSubscriber: Subscriber { | |
var subscription: Subscription? | |
func receive(subscription: Subscription) { self.subscription = subscription } | |
func receive(_ input: Int) -> Subscribers.Demand { print(input); return .none } | |
func receive(completion: Subscribers.Completion<Never>) {} | |
} | |
let subscriber = ManualSubscriber() | |
let subject = PassthroughSubject<Int, Never>() | |
subject | |
.subscribe(subscriber) | |
subscriber.subscription?.request(.max(1)) | |
subject.send(1) | |
subject.send(2) | |
subscriber.subscription?.request(.max(1)) | |
subject.send(3) | |
// Outputs: | |
// ``` | |
// 1 | |
// 3 | |
// ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment