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
| <aname="term_signal">Signal</a> | As a noun: one of the `onSubscribe`, `onNext`, `onComplete` or `onError` methods. As a verb: calling/invoking a signal. |
75
+
| <aname="term_demand">Demand</a> | As a noun, the aggregated number of elements requested by a Subscriber which is yet to be delivered (fulfilled) by the Publisher. As a verb, the act of `request`-ing more elements. |
76
+
| <aname="term_sync">Synchronous(ly)</a> | Executes on the calling Thread. |
77
+
| <aname="term_return_normally">Return normally</a> | Returns a value of the declared type alternatively throws an exception permitted by this specification. The only legal way to signal failure to a `Subscriber` is via the `onError` method.|
78
+
| <aname="term_emit_element">Emit element</a> | Signalling a value to `onNext`. |
79
+
| <aname="term_responsivity">Responsivity</a> | Readiness/ability to respond. In this document used to indicate that the different components should not impair eachothers ability to respond. |
80
+
| <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. |
81
+
| <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.|
82
+
72
83
73
84
### SPECIFICATION
74
85
@@ -94,7 +105,7 @@ public interface Publisher<T> {
94
105
| [:bulb:](#1.5"1.5 explained") |*The intent of this rule is to make it clear that a Publisher is responsible for notifying its Subscribers that it has reached a `terminal state`—Subscribers can then act on this information; clean up resources, etc.*|
95
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. |
96
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.*|
97
-
|<a name="1.7">7</a>|Once a terminal state has been signaled (`onError`, `onComplete`) it is REQUIRED that no further signals occur. |
108
+
|<a name="1.7">7</a>|Once a `terminal state` has been signaled (`onError`, `onComplete`) it is REQUIRED that no further signals occur. |
98
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.*|
99
110
|<a name="1.8">8</a>|If a `Subscription` is cancelled its `Subscriber` MUST eventually stop being signaled. |
100
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.*|
@@ -118,8 +129,8 @@ public interface Subscriber<T> {
|<a name="2.1">1</a>|A `Subscriber` MUSTsignal demand via `Subscription.request(long n)` to receive `onNext` signals. |
122
-
| [: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.*|
132
+
|<a name="2.1">1</a>|A `Subscriber` MUSTcommunicate demand via `Subscription.request(long n)` to receive `onNext` signals. |
133
+
| [:bulb:](#2.1"2.1 explained") |*The intent of this rule is to establish that it is the responsibility of the Subscriber to communicate when, and how many, elements it is able and willing to receive.*|
123
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. |
124
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.*|
125
136
|<a name="2.3">3</a>| `Subscriber.onComplete()` and `Subscriber.onError(Throwable t)` MUSTNOT call any methods on the `Subscription` or the `Publisher`.|
@@ -183,11 +194,11 @@ public interface Subscription {
183
194
|<a name="3.13">13</a>|While the `Subscription` is not cancelled, `Subscription.cancel()` MUST request the `Publisher` to eventually drop any references to the corresponding subscriber. |
184
195
| [:bulb:](#3.13"3.13 explained") |*The intent of this rule is to make sure that Subsribers can be properly garbage-collected after their subscription no longer being valid. Re-subscribing with the same Subscriber object is discouraged [see [2.12](#2.12)], but this specification does not mandate that it is disallowed since that would mean having to store previously cancelled subscriptions indefinitely.*|
185
196
|<a name="3.14">14</a>|While the `Subscription` is not cancelled, calling `Subscription.cancel` MAY cause the `Publisher`, if stateful, to transition into the `shut-down` state if no other `Subscription` exists at this point [see [1.9](#1.9)].|
186
-
| [:bulb:](#3.14"3.14 explained") |*The intent of this rule is to allow forPublishers to not accept new Subscribers in response to a cancellation signal.* |
187
-
| <a name="3.15">15</a> | Calling `Subscription.cancel` MUST return normally. The only legal way to signal failure to a `Subscriber` is via the `onError` method. |
188
-
| [:bulb:](#3.15"3.15 explained") |*The intent of this rule is to disallow implementations to throw exceptions in response to `cancel` being called, instead directing implementations to signal exceptions through the Subscriber’s `onError`.*|
189
-
|<a name="3.16">16</a>|Calling `Subscription.request` MUSTreturn normally. The only legal way to signal failure to a `Subscriber` is via the `onError` method. |
190
-
| [:bulb:](#3.16"3.16 explained") |*The intent of this rule is to disallow implementations to throw exceptions in response to `request` being called, instead directing implementations to signal exceptions through the Subscriber’s `onError`.*|
197
+
| [:bulb:](#3.14"3.14 explained") |*The intent of this rule is to allow forPublishers to signal `onComplete` or `onError` immediately following `onSubscriber` fornew Subscribers in response to a cancellation signal from an existing Subscriber.* |
198
+
| <a name="3.15">15</a> | Calling `Subscription.cancel` MUST return normally. |
199
+
| [:bulb:](#3.15"3.15 explained") |*The intent of this rule is to disallow implementations to throw exceptions in response to `cancel` being called.*|
| [:bulb:](#3.16"3.16 explained") |*The intent of this rule is to disallow implementations to throw exceptions in response to `request` being called.*|
191
202
|<a name="3.17">17</a>|A `Subscription` MUST support an unbounded number of calls to request and MUST support a demand (sum requested - sum delivered) up to 2^63-1 (`java.lang.Long.MAX_VALUE`).A demand equal or greater than 2^63-1 (`java.lang.Long.MAX_VALUE`) MAY be considered by the `Publisher` as “effectively unbounded”.|
192
203
| [:bulb:](#3.17"3.17 explained") |*The intent of this rule is to establish that the Subscriber can request an unbounded number of elements, in any increment above 0 [see [3:9](#3.9)], in any number of invocations of `request`.As it is not feasibly reachable with current or foreseen hardware within a reasonable amount of time (1 element per nanosecond would take 292 years) to fulfill a demand of 2^63-1, it is allowed for a Publisher to stop tracking demand beyond this point.*|
193
204
@@ -266,7 +277,7 @@ Then the maximum number of elements that may arrive—until more demand is signa
266
277
267
278
These bounds must be respected by a publisher independent of whether the source it represents can be backpressured or not. In the case of sources whose production rate cannot be influenced—for example clock ticks or mouse movement—the publisher must choose to either buffer or drop elements to obey the imposed bounds.
268
279
269
-
Subscribers signaling a demand for one element after the reception of an element effectively implement a Stop-and-Wait protocol where the demand signal is equivalent to acknowledgement. By providing demand for multiple elements the cost of acknowledgement is amortized. It is worth noting that the subscriber is allowed to signal demand at any point in time, allowing it to avoid unnecessary delays between the publisher and the subscriber (i.e. keeping its input buffer filled without having to wait for full round-trips).
280
+
Subscribers signaling a demand for one element after the reception of an element effectively implement a Stop-and-Wait protocol where the demand signal is equivalent to acknowledgement. By providing demand for multiple elements the cost of acknowledgement is amortized. It is worth noting that the subscriber is allowed to communicate demand at any point in time, allowing it to avoid unnecessary delays between the publisher and the subscriber (i.e. keeping its input buffer filled without having to wait for full round-trips).
0 commit comments