You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-12
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ followed by a possibly unbounded number of `onNext` signals (as requested by `Su
77
77
| <aname="term_return_normally">Return normally</a> | Only ever returns a value of the declared type to the caller. The only legal way to signal failure to a `Subscriber` is via the `onError` method.|
78
78
| <aname="term_responsivity">Responsivity</a> | Readiness/ability to respond. In this document used to indicate that the different components should not impair each others ability to respond. |
79
79
| <aname="term_non-obstructing">Non-obstructing</a> | Quality describing a method which is as quick to execute as possible—on the calling thread. This means, for example, avoids heavy computations and other things that would stall the caller´s thread of execution. |
80
-
| <aname="term_terminal_state">Terminal state</a> | For a Publisher: The point where `onComplete` or `onError` has been signalled. For a Subscriber: The point where an `onComplete` or `onError` has been received.|
80
+
| <aname="term_terminal_state">Terminal state</a> | For a Publisher: When `onComplete` or `onError` has been signalled. For a Subscriber: When an `onComplete` or `onError` has been received.|
81
81
| <aname="term_nop">NOP</a> | Execution that has no detectable effect to the calling thread, and can as such safely be called any number of times.|
|<a name="1.1">1</a>|The total number of `onNext`:s signalled by a `Publisher` to a `Subscriber` MUST be less than or equal to the total number of elements requested by that `Subscriber`´s `Subscription` at all times. |
96
+
|<a name="1.1">1</a>|The total number of `onNext`´s signalled by a `Publisher` to a `Subscriber` MUST be less than or equal to the total number of elements requested by that `Subscriber`´s `Subscription` at all times. |
97
97
| [:bulb:](#1.1"1.1 explained") |*The intent of this rule is to make it clear that Publishers cannot signal more elements than Subscribers have requested. There’s an implicit, but important, consequence to this rule:Since demand can only be fulfilled after it has been received, there’s a happens-before relationship between requesting elements and receiving elements.*|
98
98
|<a name="1.2">2</a>|A `Publisher` MAY signal fewer `onNext` than requested and terminate the `Subscription` by calling `onComplete` or `onError`.|
99
99
| [:bulb:](#1.2"1.2 explained") |*The intent of this rule is to make it clear that a Publisher cannot guarantee that it will be able to produce the number of elements requested; it simply might not be able to produce them all; it may be in a failed state; it may be empty or otherwise already completed.*|
@@ -106,9 +106,9 @@ public interface Publisher<T> {
106
106
|<a name="1.6">6</a>|If a `Publisher` signals either `onError` or `onComplete` on a `Subscriber`, that `Subscriber`’s `Subscription` MUST be considered cancelled. |
107
107
| [:bulb:](#1.6"1.6 explained") |*The intent of this rule is to make sure that a Subscription is treated the same no matter if it was cancelled, the Publisher signalled onError or onComplete.*|
108
108
|<a name="1.7">7</a>|Once a [terminal state](#term_terminal-state) has been signaled (`onError`, `onComplete`) it is REQUIRED that no further signals occur. |
109
-
| [:bulb:](#1.7"1.7 explained") |*The intent of this rule is to make sure that onError and onComplete are the final states of an interaction between Publisher and Subscriber.*|
109
+
| [:bulb:](#1.7"1.7 explained") |*The intent of this rule is to make sure that onError and onComplete are the final states of an interaction between a Publisher and Subscriber pair.*|
110
110
|<a name="1.8">8</a>|If a `Subscription` is cancelled its `Subscriber` MUST eventually stop being signaled. |
111
-
| [:bulb:](#1.8"1.8 explained") |*The intent of this rule is to make sure that Publishers respect a Subscriber’s request to cancel a Subscription when Subscription.cancel() has been called.*|
111
+
| [:bulb:](#1.8"1.8 explained") |*The intent of this rule is to make sure that Publishers respect a Subscriber’s request to cancel a Subscription when Subscription.cancel() has been called.The reason for*eventually* is because signals can have propagation delay due to being asynchronous.*|
112
112
|<a name="1.9">9</a>| `Publisher.subscribe` MUST call `onSubscribe` on the provided `Subscriber` prior to any other signals to that `Subscriber` and MUST [return normally](#term_return_normally), except when the provided `Subscriber` is `null` in which case it MUSTthrow a `java.lang.NullPointerException` to the caller, for all other situations the only legal way to signal failure (or reject the `Subscriber`) is by calling `onError` (after calling `onSubscribe`).|
113
113
| [:bulb:](#1.9"1.9 explained") |*The intent of this rule is to make sure that `onSubscribe` is always signalled before any of the other signals, so that initialization logic can be executed by the Subscriber when the signal is received. Also `onSubscribe` MUST only be called at most once, [see [2.12](#2.12)].If the supplied `Subscriber` is `null`, there is nowhere else to signal this but to the caller, which means a `java.lang.NullPointerException` must be thrown. Examples of possible situations:A stateful Publisher can be overwhelmed, bounded by a finite number of underlying resources, exhausted, or in a [terminal state](#term_terminal-state).*|
114
114
|<a name="1.10">10</a>| `Publisher.subscribe` MAY be called as many times as wanted but MUST be with a different `Subscriber` each time [see [2.12](#2.12)].|
@@ -132,7 +132,7 @@ public interface Subscriber<T> {
132
132
|<a name="2.1">1</a>|A `Subscriber` MUST signal demand via `Subscription.request(long n)` to receive `onNext` signals. |
133
133
| [:bulb:](#2.1"2.1 explained") |*The intent of this rule is to establish that it is the responsibility of the Subscriber to signal when, and how many, elements it is able and willing to receive.*|
134
134
|<a name="2.2">2</a>|If a `Subscriber` suspects that its processing of signals will negatively impact its `Publisher`’s responsivity, it is RECOMMENDED that it asynchronously dispatches its signals. |
135
-
| [:bulb:](#2.2"2.2 explained") |*The intent of this rule is that a Subscriber should not impede the progress of the Publisher from an execution point-of-view. In other words, the Subscriber should not starve the Publisher from CPU cycles.*|
135
+
| [:bulb:](#2.2"2.2 explained") |*The intent of this rule is that a Subscriber should [not obstruct](#term_non-obstructing) the progress of the Publisher from an execution point-of-view. In other words, the Subscriber should not starve the Publisher from CPU cycles.*|
136
136
|<a name="2.3">3</a>| `Subscriber.onComplete()` and `Subscriber.onError(Throwable t)` MUSTNOT call any methods on the `Subscription` or the `Publisher`.|
137
137
| [:bulb:](#2.3"2.3 explained") |*The intent of this rule is to prevent cycles and race-conditions—between Publisher, Subsription and Subscriber—during the processing of completion signals.*|
138
138
|<a name="2.4">4</a>| `Subscriber.onComplete()` and `Subscriber.onError(Throwable t)` MUST consider the Subscription cancelled after having received the signal. |
@@ -146,15 +146,15 @@ public interface Subscriber<T> {
146
146
|<a name="2.8">8</a>|A `Subscriber` MUST be prepared to receive one or more `onNext` signals after having called `Subscription.cancel()` if there are still requested elements pending [see [3.12](#3.12)]. `Subscription.cancel()` does not guarantee to perform the underlying cleaning operations immediately. |
147
147
| [:bulb:](#2.8"2.8 explained") |*The intent of this rule is to highlight that there may be a delay between calling `cancel` the Publisher seeing that.*|
148
148
|<a name="2.9">9</a>|A `Subscriber` MUST be prepared to receive an `onComplete` signal with or without a preceding `Subscription.request(long n)` call. |
149
-
| [:bulb:](#2.9"2.9 explained") |*The intent of this rule is to establish that completion is unrelated to the demand flow—this allows for streams which close early, and does not need to "poll for completion".*|
149
+
| [:bulb:](#2.9"2.9 explained") |*The intent of this rule is to establish that completion is unrelated to the demand flow—this allows for streams which complete early, and obviates the need to *poll*for completion.*|
150
150
|<a name="2.10">10</a>|A `Subscriber` MUST be prepared to receive an `onError` signal with or without a preceding `Subscription.request(long n)` call. |
151
151
| [:bulb:](#2.10"2.10 explained") |*The intent of this rule is to establish that Publisher failures may be completely unrelated to signalled demand. This means that Subscribersdo not need to poll to find out if the Publisher will not be able to fulfill its requests.*|
152
-
|<a name="2.11">11</a>|A `Subscriber` MUST make sure that all calls on its `onXXX` methods happen-before the processing of the respective signals. I.e. the Subscriber must take care of properly publishing the signal to its processing logic. |
153
-
| [:bulb:](#2.11"2.11 explained") |*The intent of this rule is to establish that it is the responsibility of the Subscriber implementation to make sure that asynchronous processing of its signals are thread safe. See [JMM definition of Happen-Before in section 17.4.5](https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5).* |
152
+
|<a name="2.11">11</a>|A `Subscriber` MUST make sure that all calls on its [signal](#term_signal) methods happen-before the processing of the respective signals. I.e. the Subscriber must take care of properly publishing the signal to its processing logic. |
153
+
| [:bulb:](#2.11"2.11 explained") |*The intent of this rule is to establish that it is the responsibility of the Subscriber implementation to make sure that asynchronous processing of its signals are thread safe. See [JMM definition of Happens-Before in section 17.4.5](https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4.5).* |
154
154
|<a name="2.12">12</a>| `Subscriber.onSubscribe` MUST be called at most once for a given `Subscriber` (based on object equality).|
155
155
| [:bulb:](#2.12"2.12 explained") |*The intent of this rule is to establish that it MUST be assumed that the same Subscriber can only be subscribed at most once.*|
156
156
|<a name="2.13">13</a>|Calling `onSubscribe`, `onNext`, `onError` or `onComplete` MUST [return normally](#term_return_normally) except when any provided parameter is `null` in which case it MUSTthrow a `java.lang.NullPointerException` to the caller, for all other situations the only legal way for a `Subscriber` to signal failure is by cancelling its `Subscription`.In the case that this rule is violated, any associated `Subscription` to the `Subscriber` MUST be considered as cancelled, and the caller MUST raise this error condition in a fashion that is adequate for the runtime environment. |
157
-
| [:bulb:](#2.13"2.13 explained") |*The intent of this rule is to establish the semantics for the methods of Subscriber and what the Publisher is allowed to do in which casethis rule is violated. By"raising this error condition in a fashion that is adequate for the runtime environment" could mean logging the erroror otherwise make someone or something aware of the situation, as the error cannot be signalled to the faulty Subscriber.*|
157
+
| [:bulb:](#2.13"2.13 explained") |*The intent of this rule is to establish the semantics for the methods of Subscriber and what the Publisher is allowed to do in which casethis rule is violated. «Raisethis error condition in a fashion that is adequate for the runtime environment» could mean logging the error—or otherwise make someone or something aware of the situation—as the error cannot be signalled to the faulty Subscriber.*|
@@ -172,11 +172,11 @@ public interface Subscription {
172
172
|<a name="3.2">2</a>|The `Subscription` MUST allow the `Subscriber` to call `Subscription.request` synchronously from within `onNext` or `onSubscribe`.|
173
173
| [:bulb:](#3.2"3.2 explained") |*The intent of this rule is to make it clear that implementations of `request` must be reentrant, to avoid stack overflows in the case of mutual recursion between `request` and `onNext` (and eventually `onComplete` / `onError`).This implies that Publishers can be `synchronous`, i.e. signalling `onNext`:s on the thread which calls `request`.*|
174
174
|<a name="3.3">3</a>| `Subscription.request` MUST place an upper bound on possible synchronous recursion between `Publisher` and `Subscriber`.|
175
-
| [:bulb:](#3.3"3.3 explained") |*The intent of this rule is to complement [see [3.2](#3.2)] by placing an upper limit on the mutual recursion between `request` and `onNext` (and eventually `onComplete` / `onError`).Implementations are RECOMMENDED to limit this mutual recursion to a depth of `1` (ONE)—for the sake of conserving stack space. An example for undesirable synchronous, open recursion would be Subscriber.onNext ->Subscription.request ->Subscriber.onNext -> …, as it very quickly would result in blowing the calling Thread´s stack.*|
175
+
| [:bulb:](#3.3"3.3 explained") |*The intent of this rule is to complement [see [3.2](#3.2)] by placing an upper limit on the mutual recursion between `request` and `onNext` (and eventually `onComplete` / `onError`).Implementations are RECOMMENDED to limit this mutual recursion to a depth of `1` (ONE)—for the sake of conserving stack space. An example for undesirable synchronous, open recursion would be Subscriber.onNext ->Subscription.request ->Subscriber.onNext -> …, as it otherwise will result in blowing the calling Thread´s stack.*|
176
176
|<a name="3.4">4</a>| `Subscription.request` SHOULD respect the responsivity of its caller by returning in a timely manner. |
177
-
| [:bulb:](#3.4"3.4 explained") |*The intent of this rule is to establish that `request` is intended to be a non-obstructing method, and should be as quick to execute as possible on the calling thread, so avoid heavy computations and other things that would stall the caller´s thread of execution.*|
177
+
| [:bulb:](#3.4"3.4 explained") |*The intent of this rule is to establish that `request` is intended to be a [non-obstructing](#term_non-obstructing) method, and should be as quick to execute as possible on the calling thread, so avoid heavy computations and other things that would stall the caller´s thread of execution.*|
178
178
|<a name="3.5">5</a>| `Subscription.cancel` MUST respect the responsivity of its caller by returning in a timely manner, MUST be idempotent and MUST be thread-safe. |
179
-
| [:bulb:](#3.5"3.5 explained") |*The intent of this rule is to establish that `cancel` is intended to be a non-obstructing method, and should be as quick to execute as possible on the calling thread, so avoid heavy computations and other things that would stall the caller´s thread of execution. Furthermore, it is also important that it is possible to call it multiple times without any adverse effects.*|
179
+
| [:bulb:](#3.5"3.5 explained") |*The intent of this rule is to establish that `cancel` is intended to be a [non-obstructing](#term_non-obstructing) method, and should be as quick to execute as possible on the calling thread, so avoid heavy computations and other things that would stall the caller´s thread of execution. Furthermore, it is also important that it is possible to call it multiple times without any adverse effects.*|
180
180
|<a name="3.6">6</a>|After the `Subscription` is cancelled, additional `Subscription.request(long n)` MUST be [NOPs](#term_nop).|
181
181
| [:bulb:](#3.6"3.6 explained") |*The intent of this rule is to establish a causal relationship between cancellation of a subscription and the subsequent non-operation of requesting more elements.*|
182
182
|<a name="3.7">7</a>|After the `Subscription` is cancelled, additional `Subscription.cancel()` MUST be [NOPs](#term_nop).|
0 commit comments