Custom Publishers and Subscribers
Build your own Combine components.
Beyond Built-in Publishers
Combine ships with many publishers, but sometimes you need to wrap a non-Combine API as a publisher, or consume values with precise backpressure control. That means implementing the Publisher and Subscriber protocols yourself.
The Publisher Protocol
A Publisher declares its Output and Failure types and implements receive(subscriber:), where it hands a subscription to the incoming subscriber.
protocol Publisher {
associatedtype Output
associatedtype Failure: Error
func receive<S: Subscriber>(subscriber: S)
where S.Input == Output, S.Failure == Failure
}All lessons in this course
- Transforming and Combining Streams
- Schedulers and Threading
- Error Handling Operators
- Custom Publishers and Subscribers