jimu-decompiled/sources/io/reactivex/internal/operators/observable/BlockingObservableNext.java
2025-05-13 19:24:51 +02:00

139 lines
4.2 KiB
Java

package io.reactivex.internal.operators.observable;
import io.reactivex.Notification;
import io.reactivex.ObservableSource;
import io.reactivex.internal.util.BlockingHelper;
import io.reactivex.internal.util.ExceptionHelper;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes2.dex */
public final class BlockingObservableNext<T> implements Iterable<T> {
final ObservableSource<T> a;
static final class NextIterator<T> implements Iterator<T> {
private final NextObserver<T> a;
private final ObservableSource<T> b;
private T c;
private boolean d = true;
private boolean e = true;
private Throwable f;
private boolean g;
NextIterator(ObservableSource<T> observableSource, NextObserver<T> nextObserver) {
this.b = observableSource;
this.a = nextObserver;
}
private boolean a() {
if (!this.g) {
this.g = true;
this.a.b();
new ObservableMaterialize(this.b).subscribe(this.a);
}
try {
Notification<T> c = this.a.c();
if (c.e()) {
this.e = false;
this.c = c.b();
return true;
}
this.d = false;
if (c.c()) {
return false;
}
this.f = c.a();
throw ExceptionHelper.a(this.f);
} catch (InterruptedException e) {
this.a.dispose();
this.f = e;
throw ExceptionHelper.a(e);
}
}
@Override // java.util.Iterator
public boolean hasNext() {
Throwable th = this.f;
if (th != null) {
throw ExceptionHelper.a(th);
}
if (this.d) {
return !this.e || a();
}
return false;
}
@Override // java.util.Iterator
public T next() {
Throwable th = this.f;
if (th != null) {
throw ExceptionHelper.a(th);
}
if (!hasNext()) {
throw new NoSuchElementException("No more elements");
}
this.e = true;
return this.c;
}
@Override // java.util.Iterator
public void remove() {
throw new UnsupportedOperationException("Read only iterator");
}
}
static final class NextObserver<T> extends DisposableObserver<Notification<T>> {
private final BlockingQueue<Notification<T>> b = new ArrayBlockingQueue(1);
final AtomicInteger c = new AtomicInteger();
NextObserver() {
}
@Override // io.reactivex.Observer
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onNext(Notification<T> notification) {
if (this.c.getAndSet(0) == 1 || !notification.e()) {
while (!this.b.offer(notification)) {
Notification<T> poll = this.b.poll();
if (poll != null && !poll.e()) {
notification = poll;
}
}
}
}
void b() {
this.c.set(1);
}
public Notification<T> c() throws InterruptedException {
b();
BlockingHelper.a();
return this.b.take();
}
@Override // io.reactivex.Observer
public void onComplete() {
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
RxJavaPlugins.b(th);
}
}
public BlockingObservableNext(ObservableSource<T> observableSource) {
this.a = observableSource;
}
@Override // java.lang.Iterable
public Iterator<T> iterator() {
return new NextIterator(this.a, new NextObserver());
}
}