86 lines
2.7 KiB
Java
86 lines
2.7 KiB
Java
package io.reactivex.internal.subscribers;
|
|
|
|
import io.reactivex.FlowableSubscriber;
|
|
import io.reactivex.internal.subscriptions.SubscriptionHelper;
|
|
import io.reactivex.internal.util.BackpressureHelper;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import org.reactivestreams.Subscriber;
|
|
import org.reactivestreams.Subscription;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public abstract class SinglePostCompleteSubscriber<T, R> extends AtomicLong implements FlowableSubscriber<T>, Subscription {
|
|
static final long COMPLETE_MASK = Long.MIN_VALUE;
|
|
static final long REQUEST_MASK = Long.MAX_VALUE;
|
|
private static final long serialVersionUID = 7917814472626990048L;
|
|
protected final Subscriber<? super R> downstream;
|
|
protected long produced;
|
|
protected Subscription upstream;
|
|
protected R value;
|
|
|
|
public SinglePostCompleteSubscriber(Subscriber<? super R> subscriber) {
|
|
this.downstream = subscriber;
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public void cancel() {
|
|
this.upstream.cancel();
|
|
}
|
|
|
|
protected final void complete(R r) {
|
|
long j = this.produced;
|
|
if (j != 0) {
|
|
BackpressureHelper.b(this, j);
|
|
}
|
|
while (true) {
|
|
long j2 = get();
|
|
if ((j2 & COMPLETE_MASK) != 0) {
|
|
onDrop(r);
|
|
return;
|
|
}
|
|
if ((j2 & REQUEST_MASK) != 0) {
|
|
lazySet(-9223372036854775807L);
|
|
this.downstream.onNext(r);
|
|
this.downstream.onComplete();
|
|
return;
|
|
} else {
|
|
this.value = r;
|
|
if (compareAndSet(0L, COMPLETE_MASK)) {
|
|
return;
|
|
} else {
|
|
this.value = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void onDrop(R r) {
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onSubscribe(Subscription subscription) {
|
|
if (SubscriptionHelper.validate(this.upstream, subscription)) {
|
|
this.upstream = subscription;
|
|
this.downstream.onSubscribe(this);
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public final void request(long j) {
|
|
long j2;
|
|
if (SubscriptionHelper.validate(j)) {
|
|
do {
|
|
j2 = get();
|
|
if ((j2 & COMPLETE_MASK) != 0) {
|
|
if (compareAndSet(COMPLETE_MASK, -9223372036854775807L)) {
|
|
this.downstream.onNext(this.value);
|
|
this.downstream.onComplete();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
} while (!compareAndSet(j2, BackpressureHelper.a(j2, j)));
|
|
this.upstream.request(j);
|
|
}
|
|
}
|
|
}
|