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 implements Iterable { final ObservableSource a; static final class BlockingObservableLatestIterator extends DisposableObserver> implements Iterator { Notification b; final Semaphore c = new Semaphore(0); final AtomicReference> d = new AtomicReference<>(); BlockingObservableLatestIterator() { } @Override // io.reactivex.Observer /* renamed from: a, reason: merged with bridge method [inline-methods] */ public void onNext(Notification notification) { if (this.d.getAndSet(notification) == null) { this.c.release(); } } @Override // java.util.Iterator public boolean hasNext() { Notification 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 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 observableSource) { this.a = observableSource; } @Override // java.lang.Iterable public Iterator iterator() { BlockingObservableLatestIterator blockingObservableLatestIterator = new BlockingObservableLatestIterator(); Observable.wrap(this.a).materialize().subscribe(blockingObservableLatestIterator); return blockingObservableLatestIterator; } }