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

Subscriber rules

Subscriber has the following interface definition:

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

Rule number 2.1 says, A Subscriber must signal demand via Subscription.request(long n) to receive onNext signals. This rule is in line with Publisher rule number 1.1 in the sense that it  establishes the responsibility of Subscriber to inform when and how many messages it is able and willing to receive.

Rule number 2.4 says, .onComplete() and Subscriber.onError(Throwable t) must consider the Subscription cancelled after having received the signal. Here again, the design intention at play is highlighted. The design sequence of sending ensures that the process of the message being sent from Publisher to Subscriber is completely decoupled. Therefore, Publisher is not bound by the Subscriber intent to keep listening, hence ensuring a non-blocking arrangement.

As soon as Publisher sends out a message, it has no messages to be sent with Subscriber.onComplete() and the Subscription object is no longer valid/available. This is similar to when an exception is thrown back with Subscriber.onError(Throwable t). The Subscription object can no longer be utilized by  Subscriber to request more messages.

It is worthwhile mentioning another couple of rules around the same design. These are rules number 2.9 and 2.10 concerning Subscription.request(long n). The rule says that a Subscriber can get the onError signal or the onComplete signal with or without a preceding call to Subscription.request(long n).

主站蜘蛛池模板: 报价| 玛多县| 瓮安县| 开封市| 江北区| 阿克| 辽宁省| 拜泉县| 新泰市| 锡林浩特市| 新田县| 巴南区| 昌乐县| 广东省| 社旗县| 四平市| 赤峰市| 丁青县| 赤水市| 磐石市| 洛隆县| 寿光市| 绥德县| 涪陵区| 蒙自县| 福州市| 行唐县| 宣汉县| 蚌埠市| 永寿县| 泰州市| 昭觉县| 民和| 东明县| 大理市| 文水县| 富顺县| 闻喜县| 贞丰县| 阳西县| 称多县|