From e7e1b87926abb2f944d0c6f9e4a87d16837dec36 Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Sun, 26 Nov 2017 16:48:19 -0800 Subject: [PATCH] Call delegate.onSubscribe() first, remove callSubscribeIfNecessary --- .../autodispose/AutoDisposingSubscriberImpl.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java index c804e313b..884f19516 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java @@ -19,7 +19,6 @@ import com.uber.autodispose.observers.AutoDisposingSubscriber; import io.reactivex.Maybe; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.observers.DisposableMaybeObserver; import java.util.concurrent.atomic.AtomicInteger; @@ -51,26 +50,24 @@ final class AutoDisposingSubscriberImpl extends AtomicInteger @Override public void onSubscribe(final Subscription s) { DisposableMaybeObserver o = new DisposableMaybeObserver() { @Override public void onSuccess(Object o) { - callMainSubscribeIfNecessary(s); AutoSubscriptionHelper.cancel(mainSubscription); lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED); } @Override public void onError(Throwable e) { - callMainSubscribeIfNecessary(s); AutoDisposingSubscriberImpl.this.onError(e); mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED); } @Override public void onComplete() { - callMainSubscribeIfNecessary(s); mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED); // Noop - we're unbound now } }; if (AutoDisposeEndConsumerHelper.setOnce(lifecycleDisposable, o, getClass())) { + delegate.onSubscribe(this); lifecycle.subscribe(o); if (AutoDisposeEndConsumerHelper.setOnce(mainSubscription, s, getClass())) { SubscriptionHelper.deferredSetOnce(ref, requested, s); @@ -101,16 +98,6 @@ final class AutoDisposingSubscriberImpl extends AtomicInteger AutoSubscriptionHelper.cancel(mainSubscription); } - @SuppressWarnings("WeakerAccess") // Avoiding synthetic accessors - void callMainSubscribeIfNecessary(Subscription s) { - // If we've never actually started the upstream subscription (i.e. requested immediately in - // onSubscribe and had a terminal event), we need to still send an empty subscription instance - // to abide by the Subscriber contract. - if (AutoSubscriptionHelper.setIfNotSet(mainSubscription, s)) { - delegate.onSubscribe(EmptySubscription.INSTANCE); - } - } - @Override public boolean isDisposed() { return mainSubscription.get() == AutoSubscriptionHelper.CANCELLED; }