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

95 lines
3.2 KiB
Java

package io.reactivex.internal.operators.observable;
import io.reactivex.Notification;
import io.reactivex.Observable;
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.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
/* loaded from: classes2.dex */
public final class BlockingObservableLatest<T> implements Iterable<T> {
final ObservableSource<T> a;
static final class BlockingObservableLatestIterator<T> extends DisposableObserver<Notification<T>> implements Iterator<T> {
Notification<T> b;
final Semaphore c = new Semaphore(0);
final AtomicReference<Notification<T>> d = new AtomicReference<>();
BlockingObservableLatestIterator() {
}
@Override // io.reactivex.Observer
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onNext(Notification<T> notification) {
if (this.d.getAndSet(notification) == null) {
this.c.release();
}
}
@Override // java.util.Iterator
public boolean hasNext() {
Notification<T> notification = this.b;
if (notification != null && notification.d()) {
throw ExceptionHelper.a(this.b.a());
}
if (this.b == null) {
try {
BlockingHelper.a();
this.c.acquire();
Notification<T> andSet = this.d.getAndSet(null);
this.b = andSet;
if (andSet.d()) {
throw ExceptionHelper.a(andSet.a());
}
} catch (InterruptedException e) {
dispose();
this.b = Notification.a((Throwable) e);
throw ExceptionHelper.a(e);
}
}
return this.b.e();
}
@Override // java.util.Iterator
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
T b = this.b.b();
this.b = null;
return b;
}
@Override // io.reactivex.Observer
public void onComplete() {
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
RxJavaPlugins.b(th);
}
@Override // java.util.Iterator
public void remove() {
throw new UnsupportedOperationException("Read-only iterator.");
}
}
public BlockingObservableLatest(ObservableSource<T> observableSource) {
this.a = observableSource;
}
@Override // java.lang.Iterable
public Iterator<T> iterator() {
BlockingObservableLatestIterator blockingObservableLatestIterator = new BlockingObservableLatestIterator();
Observable.wrap(this.a).materialize().subscribe(blockingObservableLatestIterator);
return blockingObservableLatestIterator;
}
}