A standard contract
The reactive streams specification defines how a producer and consumer exchange an unbounded sequence of items asynchronously while respecting backpressure. It is built from four roles.
The four interfaces
- A publisher produces items.
- A subscriber consumes them.
- A subscription is the link a subscriber uses to control flow.
- A processor is both a subscriber and a publisher, used for transformation.
The demand protocol
The crucial idea is that the subscriber requests a number of items through its subscription. The publisher may send at most that many. This pull within push design means a fast publisher cannot overwhelm a slow subscriber.
Signals
The subscriber receives on next for each item, on error if the stream fails, and on complete when it ends. Error and complete are terminal: nothing follows them.
Key idea
Reactive streams standardize asynchronous data flow with a publisher, subscriber, subscription, and processor, governed by explicit demand requests.