Skip to content

Commit

Permalink
Inline lazyDispose() impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Nov 18, 2017
1 parent ec190c0 commit 9606ae4
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

final class AutoDisposingSubscriberImpl<T> extends AtomicInteger implements AutoDisposingSubscriber<T> {
final class AutoDisposingSubscriberImpl<T> extends AtomicInteger
implements AutoDisposingSubscriber<T> {

private final AtomicReference<Subscription> mainSubscription = new AtomicReference<>();
private final AtomicReference<Disposable> lifecycleDisposable = new AtomicReference<>();
Expand Down Expand Up @@ -100,11 +101,6 @@ final class AutoDisposingSubscriberImpl<T> extends AtomicInteger implements Auto
AutoSubscriptionHelper.cancel(mainSubscription);
}

private void lazyCancel() {
AutoDisposableHelper.dispose(lifecycleDisposable);
mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED);
}

@SuppressWarnings("WeakerAccess") // Avoiding synthetic accessors
void callMainSubscribeIfNecessary(Subscription s) {
// If we've never actually started the upstream subscription (i.e. requested immediately in
Expand All @@ -127,21 +123,24 @@ void callMainSubscribeIfNecessary(Subscription s) {
if (!isDisposed()) {
if (HalfSerializer.onNext(delegate, value, this, error)) {
// Terminal event occurred and was forwarded to the delegate, so clean up here
lazyCancel();
AutoDisposableHelper.dispose(lifecycleDisposable);
mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED);
}
}
}

@Override public void onError(Throwable e) {
if (!isDisposed()) {
lazyCancel();
AutoDisposableHelper.dispose(lifecycleDisposable);
mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED);
HalfSerializer.onError(delegate, e, this, error);
}
}

@Override public void onComplete() {
if (!isDisposed()) {
lazyCancel();
AutoDisposableHelper.dispose(lifecycleDisposable);
mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED);
HalfSerializer.onComplete(delegate, this, error);
}
}
Expand Down

0 comments on commit 9606ae4

Please sign in to comment.