use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable in project RxJava by ReactiveX.
the class ObservableRepeat method subscribeActual.
@Override
public void subscribeActual(Observer<? super T> observer) {
SequentialDisposable sd = new SequentialDisposable();
observer.onSubscribe(sd);
RepeatObserver<T> rs = new RepeatObserver<>(observer, count != Long.MAX_VALUE ? count - 1 : Long.MAX_VALUE, sd, source);
rs.subscribeNext();
}
use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable in project RxJava by ReactiveX.
the class AbstractSchedulerTests method schedulePeriodicallyDirectZeroPeriod.
@Test
public void schedulePeriodicallyDirectZeroPeriod() throws Exception {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// can't properly stop a trampolined periodic task
return;
}
for (int initial = 0; initial < 2; initial++) {
final CountDownLatch cdl = new CountDownLatch(1);
final SequentialDisposable sd = new SequentialDisposable();
try {
sd.replace(s.schedulePeriodicallyDirect(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
}
}
}
use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable in project RxJava by ReactiveX.
the class SchedulerTest method disposeSelfPeriodicDirect.
@Test
public void disposeSelfPeriodicDirect() {
final int[] count = { 0 };
TestScheduler scheduler = new TestScheduler();
final SequentialDisposable sd = new SequentialDisposable();
Disposable d = scheduler.schedulePeriodicallyDirect(new Runnable() {
@Override
public void run() {
count[0]++;
sd.dispose();
}
}, 100, 100, TimeUnit.MILLISECONDS);
sd.set(d);
assertEquals(0, count[0]);
assertFalse(d.isDisposed());
scheduler.advanceTimeBy(400, TimeUnit.MILLISECONDS);
assertEquals(1, count[0]);
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method interruptibleRunnableRunDisposeRace.
@Test
public void interruptibleRunnableRunDisposeRace() {
ExecutorService exec = Executors.newSingleThreadExecutor();
try {
Scheduler s = Schedulers.from(r -> exec.execute(r), true);
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
SequentialDisposable sd = new SequentialDisposable();
TestHelper.race(() -> sd.update(s.scheduleDirect(() -> {
})), () -> sd.dispose());
}
} finally {
exec.shutdown();
}
}
use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable 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();
}
Aggregations