94 lines
2.3 KiB
Java
94 lines
2.3 KiB
Java
package j0.l.a;
|
|
|
|
import j0.o.l;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import rx.Producer;
|
|
import rx.Subscriber;
|
|
/* compiled from: OperatorTake */
|
|
public class b2 extends Subscriber<T> {
|
|
public int i;
|
|
public boolean j;
|
|
public final /* synthetic */ Subscriber k;
|
|
public final /* synthetic */ c2 l;
|
|
|
|
/* compiled from: OperatorTake */
|
|
public class a implements Producer {
|
|
public final AtomicLong i = new AtomicLong(0);
|
|
public final /* synthetic */ Producer j;
|
|
|
|
public a(Producer producer) {
|
|
this.j = producer;
|
|
}
|
|
|
|
@Override // rx.Producer
|
|
public void j(long j) {
|
|
long j2;
|
|
long min;
|
|
if (j > 0 && !b2.this.j) {
|
|
do {
|
|
j2 = this.i.get();
|
|
min = Math.min(j, ((long) b2.this.l.i) - j2);
|
|
if (min == 0) {
|
|
return;
|
|
}
|
|
} while (!this.i.compareAndSet(j2, j2 + min));
|
|
this.j.j(min);
|
|
}
|
|
}
|
|
}
|
|
|
|
public b2(c2 c2Var, Subscriber subscriber) {
|
|
this.l = c2Var;
|
|
this.k = subscriber;
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onCompleted() {
|
|
if (!this.j) {
|
|
this.j = true;
|
|
this.k.onCompleted();
|
|
}
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onError(Throwable th) {
|
|
if (!this.j) {
|
|
this.j = true;
|
|
try {
|
|
this.k.onError(th);
|
|
} finally {
|
|
unsubscribe();
|
|
}
|
|
} else {
|
|
l.b(th);
|
|
}
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onNext(T t) {
|
|
if (!isUnsubscribed()) {
|
|
int i = this.i;
|
|
int i2 = i + 1;
|
|
this.i = i2;
|
|
int i3 = this.l.i;
|
|
if (i < i3) {
|
|
boolean z2 = i2 == i3;
|
|
this.k.onNext(t);
|
|
if (z2 && !this.j) {
|
|
this.j = true;
|
|
try {
|
|
this.k.onCompleted();
|
|
} finally {
|
|
unsubscribe();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // rx.Subscriber
|
|
public void setProducer(Producer producer) {
|
|
this.k.setProducer(new a(producer));
|
|
}
|
|
}
|