Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix typo, rename subscribe methods
  • Loading branch information
akarnokd committed May 14, 2016
commit 9469e9a02db0fc0ee0c19abbae43a14cad8e20f7
65 changes: 33 additions & 32 deletions src/main/java/rx/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void onSubscribe(Subscription d) {
}

// no need to have separate subscribers because inner is stateless
c.subscribe(inner);
c.unsafeSubscribe(inner);
}
}
});
Expand Down Expand Up @@ -301,7 +301,7 @@ public void onSubscribe(Subscription d) {
}

// no need to have separate subscribers because inner is stateless
c.subscribe(inner);
c.unsafeSubscribe(inner);
}
}
});
Expand Down Expand Up @@ -416,7 +416,7 @@ public void call(CompletableSubscriber s) {
return;
}

c.subscribe(s);
c.unsafeSubscribe(s);
}
});
}
Expand Down Expand Up @@ -899,7 +899,7 @@ public void call(final CompletableSubscriber s) {

final AtomicBoolean once = new AtomicBoolean();

cs.subscribe(new CompletableSubscriber() {
cs.unsafeSubscribe(new CompletableSubscriber() {
Subscription d;
void dispose() {
d.unsubscribe();
Expand Down Expand Up @@ -999,7 +999,7 @@ public final void await() {
final CountDownLatch cdl = new CountDownLatch(1);
final Throwable[] err = new Throwable[1];

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1050,7 +1050,7 @@ public final boolean await(long timeout, TimeUnit unit) {
final CountDownLatch cdl = new CountDownLatch(1);
final Throwable[] err = new Throwable[1];

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ public void call(final CompletableSubscriber s) {
final Scheduler.Worker w = scheduler.createWorker();
set.add(w);

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {


@Override
Expand Down Expand Up @@ -1302,7 +1302,7 @@ protected final Completable doOnLifecycle(
return create(new CompletableOnSubscribe() {
@Override
public void call(final CompletableSubscriber s) {
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1434,7 +1434,7 @@ public final Throwable get() {
final CountDownLatch cdl = new CountDownLatch(1);
final Throwable[] err = new Throwable[1];

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1478,7 +1478,7 @@ public final Throwable get(long timeout, TimeUnit unit) {
final CountDownLatch cdl = new CountDownLatch(1);
final Throwable[] err = new Throwable[1];

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1530,7 +1530,7 @@ public void call(CompletableSubscriber s) {

CompletableSubscriber sw = onLift.call(s);

subscribe(sw);
unsafeSubscribe(sw);
} catch (NullPointerException ex) {
throw ex;
} catch (Throwable ex) {
Expand Down Expand Up @@ -1571,7 +1571,7 @@ public void call(final CompletableSubscriber s) {

s.onSubscribe(ad);

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1633,7 +1633,7 @@ public final Completable onErrorComplete(final Func1<? super Throwable, Boolean>
return create(new CompletableOnSubscribe() {
@Override
public void call(final CompletableSubscriber s) {
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1682,7 +1682,7 @@ public final Completable onErrorResumeNext(final Func1<? super Throwable, ? exte
@Override
public void call(final CompletableSubscriber s) {
final SerialSubscription sd = new SerialSubscription();
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand All @@ -1708,7 +1708,7 @@ public void onError(Throwable e) {
return;
}

c.subscribe(new CompletableSubscriber() {
c.unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -1844,7 +1844,7 @@ public final <T> Observable<T> startWith(Observable<T> other) {
*/
public final Subscription subscribe() {
final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription();
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SafeCompletableSubscriber is not used here nor the others subscribe methods, except for subscribe(Subscriber). I think subscribe methods should call between themselves (as in Observable#subscribe methods) to refactor code and avoid forgetting this kind of things.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsafeSubscribe should call between themselves too.

Copy link

@bryant1410 bryant1410 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should call subscribe now instead, doesn't it? And the others subscribe methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the rest are intermediate operators or already perform custom logic in addition to reporting the error to a plugin. Plus, this particulare use case, the subscriber is not expected to crash.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the idea of the safe subscribe is to ensure the caller that the contract will be met. Why in this particular case it won't?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But SafeSubscriber in the first line of the javadocs says:

SafeSubscriber is a wrapper around Subscriber that ensures that the Subscriber complies with the Observable contract.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. However, this method doesn't run any user supplied code and thus no need to wrap it into a safe completable subscriber.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. However, the other 2 subscribe methods that don't use SafeCompletableSubscriber should do it. To assert that the Action instances are called at most once, and not both, complying with the contract.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the safeguard to those methods.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Why not reusing SafeCompletableSubscriber?

@Override
public void onCompleted() {
mad.unsubscribe();
Expand Down Expand Up @@ -1877,7 +1877,7 @@ public final Subscription subscribe(final Action0 onComplete) {
requireNonNull(onComplete);

final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription();
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onCompleted() {
try {
Expand Down Expand Up @@ -1919,7 +1919,7 @@ public final Subscription subscribe(final Action1<? super Throwable> onError, fi
requireNonNull(onComplete);

final MultipleAssignmentSubscription mad = new MultipleAssignmentSubscription();
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onCompleted() {
try {
Expand Down Expand Up @@ -1963,7 +1963,7 @@ private static void deliverUncaughtException(Throwable e) {
* @param s the CompletableSubscriber, not null
* @throws NullPointerException if s is null
*/
public final void subscribe(CompletableSubscriber s) {
public final void unsafeSubscribe(CompletableSubscriber s) {
requireNonNull(s);
try {
// TODO plugin wrapping the subscriber
Expand All @@ -1980,11 +1980,11 @@ public final void subscribe(CompletableSubscriber s) {

/**
* Subscribes the given CompletableSubscriber to this Completable instance
* and handles exceptions throw by its onXXX methods.
* and handles exceptions thrown by its onXXX methods.
* @param s the CompletableSubscriber, not null
* @throws NullPointerException if s is null
*/
public final void safeSubscribe(CompletableSubscriber s) {
public final void subscribe(CompletableSubscriber s) {
requireNonNull(s);
try {
// TODO plugin wrapping the subscriber

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of this TODO? What is missing here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin system is half mistery to me right. I'll figure that out and add the hooks in a separate PR.

Expand All @@ -2000,12 +2000,12 @@ public final void safeSubscribe(CompletableSubscriber s) {
}

/**
* Subscribes a reactive-streams Subscriber to this Completable instance which
* Subscribes a regular Subscriber to this Completable instance which
* will receive only an onError or onComplete event.
* @param s the reactive-streams Subscriber, not null
* @throws NullPointerException if s is null
*/
public final <T> void subscribe(Subscriber<T> s) {
public final <T> void unsafeSubscribe(Subscriber<T> s) {
requireNonNull(s);
try {
final Subscriber<?> sw = s; // FIXME hooking in 1.x is kind of strange to me
Expand All @@ -2014,7 +2014,7 @@ public final <T> void subscribe(Subscriber<T> s) {
throw new NullPointerException("The RxJavaPlugins.onSubscribe returned a null Subscriber");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can only happen if s is null, which is checked in requiredNonNull(s). Same in subscribe(Subscriber)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why using sw? Is just an alias of s.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there to capture plugin errors once the plugin API is extended.

Copy link

@bryant1410 bryant1410 May 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean once there is an execution hook for Completable? Or what do you mean?

}

subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onCompleted() {
sw.onCompleted();
Expand All @@ -2041,12 +2041,13 @@ public void onSubscribe(Subscription d) {
}

/**
* Subscribes a reactive-streams Subscriber to this Completable instance which
* will receive only an onError or onComplete event.
* Subscribes a regular Subscriber to this Completable instance which
* will receive only an onError or onComplete event
* and handles exceptions thrown by its onXXX methods.
* @param s the reactive-streams Subscriber, not null
* @throws NullPointerException if s is null
*/
public final <T> void safeSubscribe(Subscriber<T> s) {
public final <T> void subscribe(Subscriber<T> s) {
requireNonNull(s);
try {
final Subscriber<?> sw = s; // FIXME hooking in 1.x is kind of strange to me
Expand All @@ -2055,7 +2056,7 @@ public final <T> void safeSubscribe(Subscriber<T> s) {
throw new NullPointerException("The RxJavaPlugins.onSubscribe returned a null Subscriber");
}

subscribe(new SafeCompletableSubscriber(new CompletableSubscriber() {
unsafeSubscribe(new SafeCompletableSubscriber(new CompletableSubscriber() {
@Override
public void onCompleted() {
sw.onCompleted();
Expand Down Expand Up @@ -2102,7 +2103,7 @@ public void call(final CompletableSubscriber s) {
@Override
public void call() {
try {
subscribe(s);
unsafeSubscribe(s);
} finally {
w.unsubscribe();
}
Expand Down Expand Up @@ -2205,7 +2206,7 @@ public final <T> Observable<T> toObservable() {
return Observable.create(new OnSubscribe<T>() {
@Override
public void call(Subscriber<? super T> s) {
subscribe(s);
unsafeSubscribe(s);
}
});
}
Expand All @@ -2222,7 +2223,7 @@ public final <T> Single<T> toSingle(final Func0<? extends T> completionValueFunc
return Single.create(new rx.Single.OnSubscribe<T>() {
@Override
public void call(final SingleSubscriber<? super T> s) {
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down Expand Up @@ -2286,7 +2287,7 @@ public final Completable unsubscribeOn(final Scheduler scheduler) {
return create(new CompletableOnSubscribe() {
@Override
public void call(final CompletableSubscriber s) {
subscribe(new CompletableSubscriber() {
unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onCompleted() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rx/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ public void onSubscribe(Subscription d) {
serial.add(main);
child.add(serial);

other.subscribe(so);
other.unsafeSubscribe(so);

return main;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void next() {
return;
}

c.subscribe(inner);
c.unsafeSubscribe(inner);
}

final class ConcatInnerSubscriber implements CompletableSubscriber {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void next() {
return;
}

a[idx].subscribe(this);
a[idx].unsafeSubscribe(this);
} while (decrementAndGet() != 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void next() {
return;
}

c.subscribe(this);
c.unsafeSubscribe(this);
} while (decrementAndGet() != 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onNext(Completable t) {

wip.getAndIncrement();

t.subscribe(new CompletableSubscriber() {
t.unsafeSubscribe(new CompletableSubscriber() {
Subscription d;
boolean innerDone;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void call(final CompletableSubscriber s) {
}
}

c.subscribe(new CompletableSubscriber() {
c.unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onSubscribe(Subscription d) {
set.add(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void call(final CompletableSubscriber s) {
continue;
}

c.subscribe(new CompletableSubscriber() {
c.unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onSubscribe(Subscription d) {
set.add(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void call(final CompletableSubscriber s) {

wip.getAndIncrement();

c.subscribe(new CompletableSubscriber() {
c.unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onSubscribe(Subscription d) {
set.add(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void call(final CompletableSubscriber s) {

wip.getAndIncrement();

c.subscribe(new CompletableSubscriber() {
c.unsafeSubscribe(new CompletableSubscriber() {
@Override
public void onSubscribe(Subscription d) {
set.add(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void call() {
if (other == null) {
s.onError(new TimeoutException());
} else {
other.subscribe(new CompletableSubscriber() {
other.unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onSubscribe(Subscription d) {
Expand All @@ -85,7 +85,7 @@ public void onCompleted() {
}
}, timeout, unit);

source.subscribe(new CompletableSubscriber() {
source.unsafeSubscribe(new CompletableSubscriber() {

@Override
public void onSubscribe(Subscription d) {
Expand Down
Loading