discord-jadx/app/src/main/java/i0/e0/a/b.java

131 lines
4.0 KiB
Java

package i0.e0.a;
import c.q.a.k.a;
import i0.d;
import i0.x;
import j0.o.o;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import rx.Producer;
import rx.Subscriber;
import rx.Subscription;
import rx.exceptions.CompositeException;
import rx.exceptions.OnCompletedFailedException;
import rx.exceptions.OnErrorFailedException;
import rx.exceptions.OnErrorNotImplementedException;
/* compiled from: CallArbiter */
public final class b<T> extends AtomicInteger implements Subscription, Producer {
private final d<T> call;
private volatile x<T> response;
private final Subscriber<? super x<T>> subscriber;
private volatile boolean unsubscribed;
public b(d<T> dVar, Subscriber<? super x<T>> subscriber) {
super(0);
this.call = dVar;
this.subscriber = subscriber;
}
public final void a(x<T> xVar) {
try {
if (!this.unsubscribed) {
this.subscriber.onNext(xVar);
}
try {
if (!this.unsubscribed) {
this.subscriber.onCompleted();
}
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException unused) {
Objects.requireNonNull(o.a.b());
} catch (Throwable th) {
a.a0(th);
Objects.requireNonNull(o.a.b());
}
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException unused2) {
Objects.requireNonNull(o.a.b());
} catch (Throwable th2) {
a.a0(th2);
try {
this.subscriber.onError(th2);
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException unused3) {
Objects.requireNonNull(o.a.b());
} catch (Throwable th3) {
a.a0(th3);
new CompositeException(th2, th3);
Objects.requireNonNull(o.a.b());
}
}
}
public void b(Throwable th) {
set(3);
if (!this.unsubscribed) {
try {
this.subscriber.onError(th);
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException unused) {
Objects.requireNonNull(o.a.b());
} catch (Throwable th2) {
a.a0(th2);
new CompositeException(th, th2);
Objects.requireNonNull(o.a.b());
}
}
}
public void c(x<T> xVar) {
while (true) {
int i = get();
if (i == 0) {
this.response = xVar;
if (compareAndSet(0, 2)) {
return;
}
} else if (i != 1) {
if (i == 2 || i == 3) {
throw new AssertionError();
}
throw new IllegalStateException(c.d.b.a.a.k("Unknown state: ", i));
} else if (compareAndSet(1, 3)) {
a(xVar);
return;
}
}
}
@Override // rx.Subscription
public boolean isUnsubscribed() {
return this.unsubscribed;
}
@Override // rx.Producer
public void j(long j) {
if (j != 0) {
while (true) {
int i = get();
if (i != 0) {
if (i == 1) {
return;
}
if (i != 2) {
if (i != 3) {
throw new IllegalStateException(c.d.b.a.a.k("Unknown state: ", i));
}
return;
} else if (compareAndSet(2, 3)) {
a(this.response);
return;
}
} else if (compareAndSet(0, 1)) {
return;
}
}
}
}
@Override // rx.Subscription
public void unsubscribe() {
this.unsubscribed = true;
this.call.cancel();
}
}