use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.
the class CompletableMergeArrayDelayError method subscribeActual.
@Override
public void subscribeActual(final CompletableObserver observer) {
final CompositeDisposable set = new CompositeDisposable();
final AtomicInteger wip = new AtomicInteger(sources.length + 1);
final AtomicThrowable errors = new AtomicThrowable();
set.add(new TryTerminateAndReportDisposable(errors));
observer.onSubscribe(set);
for (CompletableSource c : sources) {
if (set.isDisposed()) {
return;
}
if (c == null) {
Throwable ex = new NullPointerException("A completable source is null");
errors.tryAddThrowableOrReport(ex);
wip.decrementAndGet();
continue;
}
c.subscribe(new MergeInnerCompletableObserver(observer, set, errors, wip));
}
if (wip.decrementAndGet() == 0) {
errors.tryTerminateConsumer(observer);
}
}
use of io.reactivex.rxjava3.internal.util.AtomicThrowable 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.internal.util.AtomicThrowable in project RxJava by ReactiveX.
the class HalfSerializerObserverTest method onNextOnCompleteRace.
@Test
public void onNextOnCompleteRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final AtomicInteger wip = new AtomicInteger();
final AtomicThrowable error = new AtomicThrowable();
final TestObserver<Integer> to = new TestObserver<>();
to.onSubscribe(Disposable.empty());
Runnable r1 = new Runnable() {
@Override
public void run() {
HalfSerializer.onNext(to, 1, wip, error);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
HalfSerializer.onComplete(to, wip, error);
}
};
TestHelper.race(r1, r2);
to.assertComplete().assertNoErrors();
assertTrue(to.values().size() <= 1);
}
}
use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.
the class HalfSerializerObserverTest method reentrantOnNextOnError.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnError() {
final AtomicInteger wip = new AtomicInteger();
final AtomicThrowable error = new AtomicThrowable();
final Observer[] a = { null };
final TestObserver to = new TestObserver();
Observer observer = new Observer() {
@Override
public void onSubscribe(Disposable d) {
to.onSubscribe(d);
}
@Override
public void onNext(Object t) {
if (t.equals(1)) {
HalfSerializer.onError(a[0], new TestException(), wip, error);
}
to.onNext(t);
}
@Override
public void onError(Throwable t) {
to.onError(t);
}
@Override
public void onComplete() {
to.onComplete();
}
};
a[0] = observer;
observer.onSubscribe(Disposable.empty());
HalfSerializer.onNext(observer, 1, wip, error);
to.assertFailure(TestException.class, 1);
}
use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.
the class HalfSerializerObserverTest method reentrantOnNextOnComplete.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnComplete() {
final AtomicInteger wip = new AtomicInteger();
final AtomicThrowable error = new AtomicThrowable();
final Observer[] a = { null };
final TestObserver to = new TestObserver();
Observer observer = new Observer() {
@Override
public void onSubscribe(Disposable d) {
to.onSubscribe(d);
}
@Override
public void onNext(Object t) {
if (t.equals(1)) {
HalfSerializer.onComplete(a[0], wip, error);
}
to.onNext(t);
}
@Override
public void onError(Throwable t) {
to.onError(t);
}
@Override
public void onComplete() {
to.onComplete();
}
};
a[0] = observer;
observer.onSubscribe(Disposable.empty());
HalfSerializer.onNext(observer, 1, wip, error);
to.assertResult(1);
}
Aggregations