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

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.
主站蜘蛛池模板: 精河县| 柏乡县| 鄯善县| 通海县| 沁源县| 马公市| 公主岭市| 渭南市| 万荣县| 攀枝花市| 德兴市| 遂昌县| 枣强县| 开鲁县| 东乡县| 江西省| 海城市| 阿巴嘎旗| 民乐县| 鄂伦春自治旗| 东乡| 长汀县| 徐州市| 龙陵县| 濮阳市| 嘉峪关市| 永康市| 鹿泉市| 元朗区| 洪泽县| 永州市| 苍山县| 南昌市| 凌源市| 汝州市| 平山县| 和龙市| 临城县| 邯郸县| 易门县| 安新县|