use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class CompletableMergeDelayErrorIterable method subscribeActual.
@Override
public void subscribeActual(final CompletableObserver observer) {
final CompositeDisposable set = new CompositeDisposable();
observer.onSubscribe(set);
Iterator<? extends CompletableSource> iterator;
try {
iterator = Objects.requireNonNull(sources.iterator(), "The source iterator returned is null");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
observer.onError(e);
return;
}
final AtomicInteger wip = new AtomicInteger(1);
final AtomicThrowable errors = new AtomicThrowable();
set.add(new TryTerminateAndReportDisposable(errors));
for (; ; ) {
if (set.isDisposed()) {
return;
}
boolean b;
try {
b = iterator.hasNext();
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
errors.tryAddThrowableOrReport(e);
break;
}
if (!b) {
break;
}
if (set.isDisposed()) {
return;
}
CompletableSource c;
try {
c = Objects.requireNonNull(iterator.next(), "The iterator returned a null CompletableSource");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
errors.tryAddThrowableOrReport(e);
break;
}
if (set.isDisposed()) {
return;
}
wip.getAndIncrement();
c.subscribe(new MergeInnerCompletableObserver(observer, set, errors, wip));
}
if (wip.decrementAndGet() == 0) {
errors.tryTerminateConsumer(observer);
}
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableRetryPredicate method subscribeActual.
@Override
public void subscribeActual(Observer<? super T> observer) {
SequentialDisposable sa = new SequentialDisposable();
observer.onSubscribe(sa);
RepeatObserver<T> rs = new RepeatObserver<>(observer, count, predicate, sa, source);
rs.subscribeNext();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ConnectableObservable method connect.
/**
* Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
* {@link Observable} to its {@link Observer}s.
* <p>
* To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The behavior is determined by the implementor of this abstract class.</dd>
* </dl>
*
* @return the {@link Disposable} representing the connection
* @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
*/
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
ConnectConsumer cc = new ConnectConsumer();
connect(cc);
return cc.disposable;
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver observer) {
observer.onSubscribe(Disposable.empty());
// none of the following should arrive at the consumer
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(IOException.class));
order.verifyNoMoreInteractions();
TestHelper.assertError(errors, 0, CompositeException.class);
CompositeException compositeException = (CompositeException) errors.get(0);
TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
});
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
observer.onError(new IOException());
observer.onComplete();
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verifyNoMoreInteractions();
assertTrue(d.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertUndeliverable(errors, 1, IOException.class);
});
}
Aggregations