Contents

Subscriber

A protocol that declares a type that can receive input from a publisher.

Declaration

protocol Subscriber<Input, Failure> : CustomCombineIdentifierConvertible

Mentioned in

Overview

A Subscriber instance receives a stream of elements from a Publisher, along with life cycle events describing changes to their relationship. A given subscriber’s Input and Failure associated types must match the Output and Failure of its corresponding publisher.

You connect a subscriber to a publisher by calling the publisher’s subscribe(_:) method. After making this call, the publisher invokes the subscriber’s receive(subscription:) method. This gives the subscriber a Subscription instance, which it uses to demand elements from the publisher, and to optionally cancel the subscription. After the subscriber makes an initial demand, the publisher calls receive(_:), possibly asynchronously, to deliver newly-published elements. If the publisher stops publishing, it calls receive(completion:), using a parameter of type Subscribers.Completion to indicate whether publishing completes normally or with an error.

Combine provides the following subscribers as operators on the Publisher type:

Topics

Declaring supporting types

Receiving elements

Receiving life cycle events

See Also

Subscribers