package io.reactivex.internal.operators.observable; import io.reactivex.Emitter; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.BiFunction; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.plugins.RxJavaPlugins; import java.util.concurrent.Callable; /* loaded from: classes2.dex */ public final class ObservableGenerate extends Observable { final Callable a; final BiFunction, S> b; final Consumer c; public ObservableGenerate(Callable callable, BiFunction, S> biFunction, Consumer consumer) { this.a = callable; this.b = biFunction; this.c = consumer; } @Override // io.reactivex.Observable public void subscribeActual(Observer observer) { try { GeneratorDisposable generatorDisposable = new GeneratorDisposable(observer, this.b, this.c, this.a.call()); observer.onSubscribe(generatorDisposable); generatorDisposable.a(); } catch (Throwable th) { Exceptions.b(th); EmptyDisposable.error(th, observer); } } static final class GeneratorDisposable implements Emitter, Disposable { final Observer a; final BiFunction, S> b; final Consumer c; S d; volatile boolean e; boolean f; GeneratorDisposable(Observer observer, BiFunction, S> biFunction, Consumer consumer, S s) { this.a = observer; this.b = biFunction; this.c = consumer; this.d = s; } public void a() { S s = this.d; if (this.e) { this.d = null; a(s); return; } BiFunction, S> biFunction = this.b; while (!this.e) { try { s = biFunction.apply(s, this); if (this.f) { this.e = true; this.d = null; a(s); return; } } catch (Throwable th) { Exceptions.b(th); this.d = null; this.e = true; onError(th); a(s); return; } } this.d = null; a(s); } @Override // io.reactivex.disposables.Disposable public void dispose() { this.e = true; } @Override // io.reactivex.Emitter public void onError(Throwable th) { if (this.f) { RxJavaPlugins.b(th); return; } if (th == null) { th = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } this.f = true; this.a.onError(th); } private void a(S s) { try { this.c.accept(s); } catch (Throwable th) { Exceptions.b(th); RxJavaPlugins.b(th); } } } }