- Hands-On Reactive Programming with Reactor
- Rahul Sharma
- 211字
- 2021-08-13 15:22:54
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.
推薦閱讀
- 32位嵌入式系統(tǒng)與SoC設計導論
- 課課通計算機原理
- 3D Printing with RepRap Cookbook
- Learning Social Media Analytics with R
- 程序設計語言與編譯
- Windows XP中文版應用基礎
- Hands-On Machine Learning with TensorFlow.js
- 自主研拋機器人技術
- 數(shù)據(jù)掘金
- 工業(yè)機器人安裝與調(diào)試
- INSTANT Heat Maps in R:How-to
- Unity Multiplayer Games
- Learning ServiceNow
- Oracle 11g Anti-hacker's Cookbook
- Practical Network Automation