官术网_书友最值得收藏!

Stream subscriber

A subscriber is used to listen to events generated by a publisher. When a subscriber registers to a publisher, it receives events in the following order:

As a result, the subscriber has the following interface to handle all of these events:

public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}

Let's cover each of these methods in detail, as follows:

  • onSubscribe(Subscription s): As soon as a publisher has received a subscriber, it generates a subscription event. The generated subscription event is then received in the specified method.
  • onNext (T): All data events generated by a publisher are received by the subscriber in the specified method. A publisher may or may not publish a data event before closing the stream.
  • onCompletion(): This refers to the completion event, which must be handled by a subscriber. Once a completion event is received, the subscription is considered void.
  • onError(): This refers to the error event, which must be handled by a subscriber. An error can occur at any moment—while building a subscription or while generating the next data event. In any case, the publisher must send the error event. Once the event is received, the subscription is considered void.
主站蜘蛛池模板: 湛江市| 太康县| 文化| 镇坪县| 红桥区| 铁力市| 泰来县| 建湖县| 东台市| 平泉县| 城步| 屏东县| 新泰市| 伊春市| 嘉义市| 始兴县| 成安县| 桂平市| 手机| 郑州市| 安仁县| 博野县| 福州市| 万盛区| 玛沁县| 东海县| 松滋市| 綦江县| 大兴区| 泗阳县| 剑川县| 崇信县| 科技| 珲春市| 潜江市| 合阳县| 中阳县| 辛集市| 甘孜县| 榆林市| 安龙县|