Reactive Streams (www.reactive-streams.org)
- is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure
- this encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols
4 Interfaces of Reactive Streams API
The Reactive Streams API consists of just 4 high interfaces:
- Publisher - is a provider of a potentially unbounded number of sequenced elements, publishing them according to the demand received from its Subscribers
- Subscriber - will receive call to Subscriber.onSubscribe(Subscription) once after passing an instance of Subscriber to Publisher.subscribe(Subscriber)
- Subscription - represents a one-to-one lifecycle of a Subscriber subscribing to a Publisher
- Processor - represents a processing stage—which is both a Subscriber and a Publisher and obeys the contracts of both
public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
public interface Subscription {
public void request(long n);
public void cancel();
}