Skip to content

Commit e285a7b

Browse files
committed
Modify OnSubscribeToObservableFuture to return early if unsubscribe without emitting anything
1 parent 2d11791 commit e285a7b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

rxjava-core/src/main/java/rx/operators/OnSubscribeToObservableFuture.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public void call() {
6262
}
6363
}));
6464
try {
65+
//don't block or propagate CancellationException if already unsubscribed
66+
if (subscriber.isUnsubscribed()) {
67+
return;
68+
}
6569
T value = (unit == null) ? (T) that.get() : (T) that.get(time, unit);
6670
subscriber.onNext(value);
6771
subscriber.onCompleted();
@@ -71,6 +75,10 @@ public void call() {
7175
// since it's already subscribed.
7276
// If the Future is canceled in other place, CancellationException will be still
7377
// passed to the final Subscriber.
78+
if (subscriber.isUnsubscribed()) {
79+
//refuse to emit onError if already unsubscribed
80+
return;
81+
}
7482
subscriber.onError(e);
7583
}
7684
}

0 commit comments

Comments
 (0)