Let’s Build a Custom Publisher in Combine

Let’s Build a Custom Publisher in Combine

After getting started with Combine, making a few network calls, and perhaps trying out the Timer publisher or KVO, eventually you’ll reach a point where you reach for a custom Publisher to solve your problem. You might have used ReactiveSwift or RxSwift and found yourself missing one of the many useful operators they provide. Maybe you’d even like to try your hand at contributing one to CombineExt!

[…]

We now have all the pieces we need: a Subscription, a Subscriber, and demand that needs to be satisfied. So what can we do with a Subscribers.Demand value?

[…]

This is why I described Subscribers.Demand as being “like a special integer.” A regular integer will always get smaller when you subtract from it, but Subscribers.Demand.unlimited will always remain unlimited, regardless of what you add to or subtract from it. ↩︎