AI-generated Key Takeaways
-
Flow.Publisher
represents a producer of items received byFlow.Subscriber
instances, delivering items in the same order to each subscriber. -
If an error prevents item delivery, subscribers receive an
onError
signal, followed by no further messages; otherwise, they receive anonComplete
signal when no more items are expected. -
Publishers can differ in how they handle drops (e.g., resource limitations) and whether new subscribers receive previously produced items.
-
The
subscribe
method allows adding a subscriber, which can then request items and unsubscribe using the providedFlow.Subscription
. -
Subscribing with a
null
subscriber or facing policy violations during subscription results in anIllegalStateException
or aNullPointerException
, respectively, sent to the subscriber'sonError
method.
Known Indirect Subclasses
Flow.Processor<T, R>
|
A producer of items (and related control messages) received by
Subscribers. Each current Flow.Subscriber
receives the same
items (via method onNext
) in the same order, unless
drops or errors are encountered. If a Publisher encounters an
error that does not allow items to be issued to a Subscriber,
that Subscriber receives onError
, and then receives no
further messages. Otherwise, when it is known that no further
messages will be issued to it, a subscriber receives onComplete
. Publishers ensure that Subscriber method
invocations for each subscription are strictly ordered in happens-before
order.
Publishers may vary in policy about whether drops (failures to issue an item because of resource limitations) are treated as unrecoverable errors. Publishers may also vary about whether Subscribers receive items that were produced or available before they subscribed.
Public Method Summary
abstract void |
Public Methods
public abstract void subscribe (Subscriber<? super T> subscriber)
Adds the given Subscriber if possible. If already
subscribed, or the attempt to subscribe fails due to policy
violations or errors, the Subscriber's onError
method is invoked with an IllegalStateException
.
Otherwise, the Subscriber's onSubscribe
method is
invoked with a new Flow.Subscription
. Subscribers may
enable receiving items by invoking the request
method of this Subscription, and may unsubscribe by
invoking its cancel
method.
Parameters
subscriber | the subscriber |
---|
Throws
NullPointerException | if subscriber is null |
---|