package io.reactivex.internal.operators.observable; import io.reactivex.ObservableSource; import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.internal.util.NotificationLite; import io.reactivex.observers.DefaultObserver; import java.util.Iterator; import java.util.NoSuchElementException; /* loaded from: classes2.dex */ public final class BlockingObservableMostRecent implements Iterable { final ObservableSource a; final T b; static final class MostRecentObserver extends DefaultObserver { volatile Object b; final class Iterator implements java.util.Iterator { private Object a; Iterator() { } @Override // java.util.Iterator public boolean hasNext() { this.a = MostRecentObserver.this.b; return !NotificationLite.isComplete(this.a); } @Override // java.util.Iterator public T next() { try { if (this.a == null) { this.a = MostRecentObserver.this.b; } if (NotificationLite.isComplete(this.a)) { throw new NoSuchElementException(); } if (NotificationLite.isError(this.a)) { throw ExceptionHelper.a(NotificationLite.getError(this.a)); } return (T) NotificationLite.getValue(this.a); } finally { this.a = null; } } @Override // java.util.Iterator public void remove() { throw new UnsupportedOperationException("Read only iterator"); } } MostRecentObserver(T t) { this.b = NotificationLite.next(t); } public MostRecentObserver.Iterator b() { return new Iterator(); } @Override // io.reactivex.Observer public void onComplete() { this.b = NotificationLite.complete(); } @Override // io.reactivex.Observer public void onError(Throwable th) { this.b = NotificationLite.error(th); } @Override // io.reactivex.Observer public void onNext(T t) { this.b = NotificationLite.next(t); } } public BlockingObservableMostRecent(ObservableSource observableSource, T t) { this.a = observableSource; this.b = t; } @Override // java.lang.Iterable public Iterator iterator() { MostRecentObserver mostRecentObserver = new MostRecentObserver(this.b); this.a.subscribe(mostRecentObserver); return mostRecentObserver.b(); } }