11.6 · Combine versus async/await, and testing pipelines
Combine is still in many codebases and still asked about, but it is no longer the default tool for new asynchronous code. The skill is knowing where it earns its place.
Mental model. Streams of many values over time with operators are Combine’s strength. One result, or an ordered sequence you consume is async/await’s.
Choosing and testing
When to use Combine, async sequences or observation, and how to test pipelines.
- When do you use Combine, AsyncSequence or the Observation framework, and when should you not use Combine?
Combine is a push-based, operator-rich framework: it models a value changing over time and composes streams declaratively (combineLatest, debounce… - How do you test Combine pipelines, and what is a TestScheduler pattern?
A pipeline is easiest to test when its inputs and its scheduler are injected. The simplest tests are synchronous: feed a PassthroughSubject or an array…
More in Combine
- 11.1 · Publisher, Subscriber, Subscription and demand
- 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.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