Group Group Group Group Group Group Group Group Group

Chapter 2: PassthroughSubject

I’m not seeing the “Still there?” that the book says should be printing in the example. I looked through the code but didn’t see anything I missed… Can I get another set of eyes on this?

example(of: "PassthroughSubject") {
    enum MyError: Error {
        case test
    }
    
    final class StringSubscriber: Subscriber {
        typealias Input = String
        typealias Failure = MyError
        
        func receive(subscription: Subscription) {
            subscription.request(.max(2))
        }
        
        func receive(_ input: String) -> Subscribers.Demand {
            print("Received value", input)
            
            return input == "World" ? .max(1) : .none
        }
        
        func receive(completion: Subscribers.Completion<MyError>) {
            print("Received completion", completion)
        }
    }
    
    let subscriber = StringSubscriber()
    
    let subject = PassthroughSubject<String, MyError>()
    
    subject.subscribe(subscriber)
    
    let subscription = subject
        .sink(
            receiveCompletion: { completion in
                print("Received completion (sink)", completion)
            },
            receiveValue: { value in
                print("Received value (sink)", value)
            }
        )

    subject.send("Hello")
    subject.send("Brent")
    
    subscription.cancel()
    
    subject.send("Still there?")
}

and the output I get is:

——— Example of: PassthroughSubject ———
Received value Hello
Received value (sink) Hello
Received value Brent
Received value (sink) Brent