org.reactivestreams.Subscriber Maven / Gradle / Ivy
package org.reactivestreams;
/**
* Will receive call to {@link #onSubscribe(Subscription)} once after passing an instance of {@link Subscriber} to {@link Publisher#subscribe(Subscriber)}.
*
* No further notifications will be received until {@link Subscription#request(int)} is called.
*
* After signaling demand:
*
* - One or more invocations of {@link #onNext(Object)} up to the maximum number defined by {@link Subscription#request(int)}
* - Single invocation of {@link #onError(Throwable)} or {@link Subscriber#onComplete()} which signals a terminal state after which no further events will be sent.
*
*
* Demand can be signaled via {@link Subscription#request(int)} whenever the {@link Subscriber} instance is capable of handling more.
*
* @param the Type of element signaled.
*/
public interface Subscriber {
/**
* Invoked after calling {@link Publisher#subscribe(Subscriber)}.
*
* No data will start flowing until {@link Subscription#request(int)} is invoked.
*
* It is the responsibility of this {@link Subscriber} instance to call {@link Subscription#request(int)} whenever more data is wanted.
*
* The {@link Publisher} will send notifications only in response to {@link Subscription#request(int)}.
*
* @param s
* {@link Subscription} that allows requesting data via {@link Subscription#request(int)}
*/
public void onSubscribe(Subscription s);
/**
* Data notification sent by the {@link Publisher} in response to requests to {@link Subscription#request(int)}.
*
* @param t the element signaled
*/
public void onNext(T t);
/**
* Failed terminal state.
*
* It is up to implementer to decide whether to cancel subscription or use {@link Subscription#request(int)}
* and expect further notifications.
*
* @param t the throwable signaled
*/
public void onError(Throwable t);
/**
* Successful terminal state.
*
* No further events will be sent even if {@link Subscription#request(int)} is invoked again.
*/
public void onComplete();
}