use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompositeDisposableTest method shouldUnsubscribeAll.
@Test
public void shouldUnsubscribeAll() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
final CompositeDisposable cd = new CompositeDisposable();
final int count = 10;
final CountDownLatch start = new CountDownLatch(1);
for (int i = 0; i < count; i++) {
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
}));
}
final List<Thread> threads = new ArrayList<>();
for (int i = 0; i < count; i++) {
final Thread t = new Thread() {
@Override
public void run() {
try {
start.await();
cd.dispose();
} catch (final InterruptedException e) {
fail(e.getMessage());
}
}
};
t.start();
threads.add(t);
}
start.countDown();
for (final Thread t : threads) {
t.join();
}
assertEquals(count, counter.get());
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable 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.disposables.CompositeDisposable 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.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompletableTimeoutTest method ambRace.
@Test
public void ambRace() {
TestObserver<Void> to = new TestObserver<>();
to.onSubscribe(Disposable.empty());
CompositeDisposable cd = new CompositeDisposable();
AtomicBoolean once = new AtomicBoolean();
TimeOutObserver a = new TimeOutObserver(cd, once, to);
a.onComplete();
a.onComplete();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
a.onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompletableAmbTest method ambRace.
@Test
public void ambRace() {
TestObserver<Void> to = new TestObserver<>();
to.onSubscribe(Disposable.empty());
CompositeDisposable cd = new CompositeDisposable();
AtomicBoolean once = new AtomicBoolean();
Amb a = new Amb(once, cd, to);
a.onSubscribe(Disposable.empty());
a.onComplete();
a.onComplete();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
a.onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations