src/main/java/io/reactivex/internal/subscriptions/SubscriptionArbiter.java
public final void setSubscription(Subscription s) {
        if (cancelled) {
            s.cancel();
            return;
        }

        ObjectHelper.requireNonNull(s, "s is null");

        if (get() == 0 && compareAndSet(0, 1)) {
            Subscription a = actual;

            if (a != null && cancelOnReplace) {
                a.cancel();
            }

            actual = s;

            long r = requested;

            if (decrementAndGet() != 0) {
                drainLoop();
            }

            if (r != 0L) {
                s.request(r);
            }

            return;
        }

        Subscription a = missedSubscription.getAndSet(s);
        if (a != null && cancelOnReplace) {
            a.cancel();
        }
        drain();
    }
public final void setSubscription(Subscription s) {
        if (cancelled) {
            s.cancel();
            return;
        }

        ObjectHelper.requireNonNull(s, "s is null");

        if (get() == 0 && compareAndSet(0, 1)) {
            Subscription a = actual;

            if (a != null && cancelOnReplace) {
                a.cancel();
            }

            actual = s;

            long r = requested;

            if (decrementAndGet() != 0) {
                drainLoop();
            }

            if (r != 0L) {
                s.request(r);
            }

            return;
        }

        Subscription a = missedSubscription.getAndSet(s);
        if (a != null && cancelOnReplace) {
            a.cancel();
        }
        drain();
    }
Atomically sets a new subscription.
@param s the subscription to set, not null (verified)