11.1 · Publisher, Subscriber, Subscription and demand
Combine is a small protocol model with a large operator library on top. Once you know the four types and who talks to whom, every pipeline reads the same way.
Mental model. A publisher is a recipe, not a stream. Nothing happens until a subscriber attaches, and then the subscriber controls the pace by requesting demand.
The protocols
Who creates what, and when anything runs.
- What are Publisher, Subscriber, Subscription and Subscriber.Input/Failure, and when does a pipeline actually start?
A Publisher declares an Output type and a Failure type (Never if it cannot fail) and one method, receive(subscriber:). A Subscriber has matching Input and…
Backpressure
Demand, and what happens when the consumer is slow.
- What is demand and backpressure in Combine, and how does a custom subscriber control it?
Backpressure is the mechanism by which a slow consumer limits a fast producer. In Combine it is demand: a Subscribers.Demand is a count (.max(n)), .unlimited…
More in Combine
- 11.2 · map, scan, combineLatest, flatMap, switchToLatest, debounce, share
- 11.3 · PassthroughSubject, CurrentValueSubject and @Published
- 11.4 · receive(on:), subscribe(on:) and where code runs
- 11.5 · AnyCancellable, subscription lifetime, and failure versus Never
- 11.6 · Combine versus async/await, and testing pipelines
- 11.7 · Operator behaviour, error placement, retry, flatMap limits and debugging
- 11.8 · Future versus Deferred, subject replay, share, and bridging to async
- 11.9 · Which thread each stage runs on, schedulers, throttle versus debounce, and timers
- 11.10 · Cancelling and completing, the cycle that survives a deinit, and failure types