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
cancelled being true here is impossible because the only way to get that
true is by submitting a Subscription to the Subscriber that happens once
and under this condition.
Copy file name to clipboardExpand all lines: examples/src/main/java/org/reactivestreams/example/unicast/AsyncStreamPublisher.java
+26-28
Original file line number
Diff line number
Diff line change
@@ -126,38 +126,36 @@ private void doCancel() {
126
126
}
127
127
128
128
// Instead of executing `subscriber.onSubscribe` synchronously from within `Publisher.subscribe`
129
-
// we execute it asynchronously, this is to avoid executing the user code (`Iterable.iterator`) on the calling thread.
129
+
// we execute it asynchronously, this is to avoid executing the user code (`supplier`) on the calling thread.
130
130
// It also makes it easier to follow rule 1.9
131
131
privatevoiddoSubscribe() {
132
-
if (!cancelled) {
133
-
// Deal with setting up the subscription with the subscriber
134
-
try {
135
-
subscriber.onSubscribe(this);
136
-
} catch (finalThrowablet) { // Due diligence to obey 2.13
137
-
terminateDueTo(newIllegalStateException(subscriber + " violated the Reactive Streams rule 2.13 by throwing an exception from onSubscribe.", t));
138
-
}
132
+
// Deal with setting up the subscription with the subscriber
133
+
try {
134
+
subscriber.onSubscribe(this);
135
+
} catch (finalThrowablet) { // Due diligence to obey 2.13
136
+
terminateDueTo(newIllegalStateException(subscriber + " violated the Reactive Streams rule 2.13 by throwing an exception from onSubscribe.", t));
137
+
}
139
138
140
-
// Deal with already complete iterators promptly
141
-
booleanhasElements = false;
142
-
try {
143
-
// Try to fetch an element from a stream to ensure the stream is not empty,
144
-
// this will be sent by the first calling of doSend
145
-
nextElementToBeSent = supplier.get();
146
-
hasElements = nextElementToBeSent != null;
147
-
} catch (finalThrowablet) {
148
-
terminateDueTo(t); // If hasNext throws, there's something wrong and we need to signal onError as per 1.2, 1.4
149
-
return;
150
-
}
139
+
// Deal with already complete iterators promptly
140
+
booleanhasElements = false;
141
+
try {
142
+
// Try to fetch an element from a stream to ensure the stream is not empty,
143
+
// this will be sent by the first calling of doSend
144
+
nextElementToBeSent = supplier.get();
145
+
hasElements = nextElementToBeSent != null;
146
+
} catch (finalThrowablet) {
147
+
terminateDueTo(t); // If hasNext throws, there's something wrong and we need to signal onError as per 1.2, 1.4
148
+
return;
149
+
}
151
150
152
-
// If we don't have anything to deliver, we're already done, so lets do the right thing and
153
-
// not wait for demand to deliver `onComplete` as per rule 1.2 and 1.3
154
-
if (!hasElements) {
155
-
try {
156
-
doCancel(); // Rule 1.6 says we need to consider the `Subscription` cancelled when `onComplete` is signalled
157
-
subscriber.onComplete();
158
-
} catch (finalThrowablet) { // As per rule 2.13, `onComplete` is not allowed to throw exceptions, so we do what we can, and log this.
159
-
(newIllegalStateException(subscriber + " violated the Reactive Streams rule 2.13 by throwing an exception from onComplete.", t)).printStackTrace(System.err);
160
-
}
151
+
// If we don't have anything to deliver, we're already done, so lets do the right thing and
152
+
// not wait for demand to deliver `onComplete` as per rule 1.2 and 1.3
153
+
if (!hasElements) {
154
+
try {
155
+
doCancel(); // Rule 1.6 says we need to consider the `Subscription` cancelled when `onComplete` is signalled
156
+
subscriber.onComplete();
157
+
} catch (finalThrowablet) { // As per rule 2.13, `onComplete` is not allowed to throw exceptions, so we do what we can, and log this.
158
+
(newIllegalStateException(subscriber + " violated the Reactive Streams rule 2.13 by throwing an exception from onComplete.", t)).printStackTrace(System.err);
0 commit comments