186 lines
5.4 KiB
Java
186 lines
5.4 KiB
Java
package j0.l.a;
|
|
|
|
import j0.g;
|
|
import j0.l.e.m.f;
|
|
import j0.l.e.n.s;
|
|
import j0.l.e.n.y;
|
|
import java.util.Queue;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import rx.Observable;
|
|
import rx.Producer;
|
|
import rx.Subscriber;
|
|
import rx.functions.Func0;
|
|
import rx.functions.Func2;
|
|
/* compiled from: OperatorScan */
|
|
public final class o1<R, T> implements Observable.b<R, T> {
|
|
public static final Object i = new Object();
|
|
public final Func0<R> j;
|
|
public final Func2<R, ? super T, R> k;
|
|
|
|
/* compiled from: OperatorScan */
|
|
public class a implements Func0<R> {
|
|
public final /* synthetic */ Object i;
|
|
|
|
public a(Object obj) {
|
|
this.i = obj;
|
|
}
|
|
|
|
@Override // rx.functions.Func0, java.util.concurrent.Callable
|
|
public R call() {
|
|
return (R) this.i;
|
|
}
|
|
}
|
|
|
|
/* compiled from: OperatorScan */
|
|
public static final class b<R> implements Producer, g<R> {
|
|
public final Subscriber<? super R> i;
|
|
public final Queue<Object> j;
|
|
public boolean k;
|
|
public boolean l;
|
|
public long m;
|
|
public final AtomicLong n;
|
|
public volatile Producer o;
|
|
public volatile boolean p;
|
|
public Throwable q;
|
|
|
|
public b(R r, Subscriber<? super R> subscriber) {
|
|
this.i = subscriber;
|
|
Queue<Object> sVar = y.b() ? new s<>() : new f<>();
|
|
this.j = sVar;
|
|
sVar.offer(r == null ? (R) e.b : r);
|
|
this.n = new AtomicLong();
|
|
}
|
|
|
|
public boolean a(boolean z2, boolean z3, Subscriber<? super R> subscriber) {
|
|
if (subscriber.isUnsubscribed()) {
|
|
return true;
|
|
}
|
|
if (!z2) {
|
|
return false;
|
|
}
|
|
Throwable th = this.q;
|
|
if (th != null) {
|
|
subscriber.onError(th);
|
|
return true;
|
|
} else if (!z3) {
|
|
return false;
|
|
} else {
|
|
subscriber.onCompleted();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public void b() {
|
|
synchronized (this) {
|
|
if (this.k) {
|
|
this.l = true;
|
|
return;
|
|
}
|
|
this.k = true;
|
|
}
|
|
Subscriber<? super R> subscriber = this.i;
|
|
Queue<Object> queue = this.j;
|
|
AtomicLong atomicLong = this.n;
|
|
long j = atomicLong.get();
|
|
while (!a(this.p, queue.isEmpty(), subscriber)) {
|
|
long j2 = 0;
|
|
while (j2 != j) {
|
|
boolean z2 = this.p;
|
|
Object poll = queue.poll();
|
|
boolean z3 = poll == null;
|
|
if (!a(z2, z3, subscriber)) {
|
|
if (z3) {
|
|
break;
|
|
}
|
|
Object obj = (Object) e.b(poll);
|
|
try {
|
|
subscriber.onNext(obj);
|
|
j2++;
|
|
} catch (Throwable th) {
|
|
c.q.a.k.a.b0(th, subscriber, obj);
|
|
return;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
if (!(j2 == 0 || j == Long.MAX_VALUE)) {
|
|
j = c.q.a.k.a.I(atomicLong, j2);
|
|
}
|
|
synchronized (this) {
|
|
if (!this.l) {
|
|
this.k = false;
|
|
return;
|
|
}
|
|
this.l = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // rx.Producer
|
|
public void j(long j) {
|
|
int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
|
|
if (i < 0) {
|
|
throw new IllegalArgumentException(c.d.b.a.a.q("n >= required but it was ", j));
|
|
} else if (i != 0) {
|
|
c.q.a.k.a.p(this.n, j);
|
|
Producer producer = this.o;
|
|
if (producer == null) {
|
|
synchronized (this.n) {
|
|
producer = this.o;
|
|
if (producer == null) {
|
|
this.m = c.q.a.k.a.d(this.m, j);
|
|
}
|
|
}
|
|
}
|
|
if (producer != null) {
|
|
producer.j(j);
|
|
}
|
|
b();
|
|
}
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onCompleted() {
|
|
this.p = true;
|
|
b();
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onError(Throwable th) {
|
|
this.q = th;
|
|
this.p = true;
|
|
b();
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onNext(R r) {
|
|
Queue<Object> queue = this.j;
|
|
if (r == null) {
|
|
r = (R) e.b;
|
|
}
|
|
queue.offer(r);
|
|
b();
|
|
}
|
|
}
|
|
|
|
public o1(R r, Func2<R, ? super T, R> func2) {
|
|
this.j = new a(r);
|
|
this.k = func2;
|
|
}
|
|
|
|
@Override // j0.k.b
|
|
public Object call(Object obj) {
|
|
Subscriber subscriber = (Subscriber) obj;
|
|
R call = this.j.call();
|
|
if (call == i) {
|
|
return new p1(this, subscriber, subscriber);
|
|
}
|
|
b bVar = new b(call, subscriber);
|
|
q1 q1Var = new q1(this, call, bVar);
|
|
subscriber.add(q1Var);
|
|
subscriber.setProducer(bVar);
|
|
return q1Var;
|
|
}
|
|
}
|