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

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).

主站蜘蛛池模板: 增城市| 福泉市| 仪征市| 文化| 石城县| 浦东新区| 环江| 长沙市| 饶河县| 六盘水市| 南昌市| 陕西省| 黔江区| 肇州县| 儋州市| 运城市| 团风县| 平利县| 景德镇市| 兰西县| 紫金县| 玛纳斯县| 扬州市| 萍乡市| 福清市| 金门县| 从化市| 柳州市| 贵南县| 南涧| 皋兰县| 紫云| 北京市| 通河县| 甘孜县| 思茅市| 秦皇岛市| 古交市| 麦盖提县| 乌恰县| 蓝山县|