Skip to content

Commit b9afc5a

Browse files
committed
Rename SyncSybscriber.foreach to whenNext
1 parent 4264e1d commit b9afc5a

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

examples/src/main/java/org/reactivestreams/example/unicast/AsyncSubscriber.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected AsyncSubscriber(Executor executor) {
5050
// herefor we also need to cancel our `Subscription`.
5151
private final void done() {
5252
//On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to.
53-
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
53+
done = true; // If `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
5454
if (subscription != null) { // If we are bailing out before we got a `Subscription` there's little need for cancelling it.
5555
try {
5656
subscription.cancel(); // Cancel the subscription

examples/src/main/java/org/reactivestreams/example/unicast/SyncSubscriber.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class SyncSubscriber<T> implements Subscriber<T> {
4949

5050
if (!done) { // If we aren't already done
5151
try {
52-
if (foreach(element)) {
52+
if (whenNext(element)) {
5353
try {
5454
subscription.request(1); // Our Subscriber is unbuffered and modest, it requests one element at a time
5555
} catch (final Throwable t) {
@@ -76,7 +76,7 @@ public abstract class SyncSubscriber<T> implements Subscriber<T> {
7676
// herefor we also need to cancel our `Subscription`.
7777
private void done() {
7878
//On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to.
79-
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
79+
done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
8080
try {
8181
subscription.cancel(); // Cancel the subscription
8282
} catch(final Throwable t) {
@@ -87,7 +87,7 @@ private void done() {
8787

8888
// This method is left as an exercise to the reader/extension point
8989
// Returns whether more elements are desired or not, and if no more elements are desired
90-
protected abstract boolean foreach(final T element);
90+
protected abstract boolean whenNext(final T element);
9191

9292
@Override public void onError(final Throwable t) {
9393
if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec

examples/src/test/java/org/reactivestreams/example/unicast/SyncSubscriberTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public SyncSubscriberTest() {
2424
@Override public Subscriber<Integer> createSubscriber() {
2525
return new SyncSubscriber<Integer>() {
2626
private long acc;
27-
@Override protected boolean foreach(final Integer element) {
27+
@Override protected boolean whenNext(final Integer element) {
2828
acc += element;
2929
return true;
3030
}

examples/src/test/java/org/reactivestreams/example/unicast/SyncSubscriberWhiteboxTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void onComplete() {
6262
}
6363

6464
@Override
65-
protected boolean foreach(Integer element) {
65+
protected boolean whenNext(Integer element) {
6666
return true;
6767
}
6868
};

tck/src/test/java/org/reactivestreams/tck/support/SyncTriggeredDemandSubscriber.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* SyncTriggeredDemandSubscriber is an implementation of Reactive Streams `Subscriber`,
88
* it runs synchronously (on the Publisher's thread) and requests demand triggered from
99
* "the outside" using its `triggerDemand` method and from "the inside" using the return
10-
* value of its user-defined `foreach` method which is invoked to process each element.
10+
* value of its user-defined `whenNext` method which is invoked to process each element.
1111
*
1212
* NOTE: The code below uses a lot of try-catches to show the reader where exceptions can be expected, and where they are forbidden.
1313
*/
@@ -85,7 +85,7 @@ else if (need == 0) {}
8585
// herefor we also need to cancel our `Subscription`.
8686
private void done() {
8787
//On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to.
88-
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
88+
done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
8989
try {
9090
subscription.cancel(); // Cancel the subscription
9191
} catch(final Throwable t) {

0 commit comments

Comments
 (0)