Skip to content

Fix 'foreach' comment in AsyncSubscriber and rename SyncSybscriber.foreach to whenNext #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CopyrightWaivers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ ldaley | Luke Daley, [email protected], Gradleware Inc.
colinrgodsey | Colin Godsey, [email protected], MediaMath Inc.
davidmoten | Dave Moten, [email protected]
briantopping | Brian Topping, [email protected], Mauswerks LLC
rstoyanchev | Rossen Stoyanchev, [email protected], Pivotal
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected AsyncSubscriber(Executor executor) {
// herefor we also need to cancel our `Subscription`.
private final void done() {
//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.
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
done = true; // If `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
if (subscription != null) { // If we are bailing out before we got a `Subscription` there's little need for cancelling it.
try {
subscription.cancel(); // Cancel the subscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class SyncSubscriber<T> implements Subscriber<T> {

if (!done) { // If we aren't already done
try {
if (foreach(element)) {
if (whenNext(element)) {
try {
subscription.request(1); // Our Subscriber is unbuffered and modest, it requests one element at a time
} catch (final Throwable t) {
Expand All @@ -76,7 +76,7 @@ public abstract class SyncSubscriber<T> implements Subscriber<T> {
// herefor we also need to cancel our `Subscription`.
private void done() {
//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.
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
try {
subscription.cancel(); // Cancel the subscription
} catch(final Throwable t) {
Expand All @@ -87,7 +87,7 @@ private void done() {

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

@Override public void onError(final Throwable t) {
if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SyncSubscriberTest() {
@Override public Subscriber<Integer> createSubscriber() {
return new SyncSubscriber<Integer>() {
private long acc;
@Override protected boolean foreach(final Integer element) {
@Override protected boolean whenNext(final Integer element) {
acc += element;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onComplete() {
}

@Override
protected boolean foreach(Integer element) {
protected boolean whenNext(Integer element) {
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SyncTriggeredDemandSubscriber is an implementation of Reactive Streams `Subscriber`,
* it runs synchronously (on the Publisher's thread) and requests demand triggered from
* "the outside" using its `triggerDemand` method and from "the inside" using the return
* value of its user-defined `foreach` method which is invoked to process each element.
* value of its user-defined `whenNext` method which is invoked to process each element.
*
* NOTE: The code below uses a lot of try-catches to show the reader where exceptions can be expected, and where they are forbidden.
*/
Expand Down Expand Up @@ -85,7 +85,7 @@ else if (need == 0) {}
// herefor we also need to cancel our `Subscription`.
private void done() {
//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.
done = true; // If we `foreach` throws an exception, let's consider ourselves done (not accepting more elements)
done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements)
try {
subscription.cancel(); // Cancel the subscription
} catch(final Throwable t) {
Expand Down