use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method runnableDisposedAsyncTimed.
@Test(timeout = 1000)
public void runnableDisposedAsyncTimed() throws Exception {
final Scheduler s = Schedulers.from(new Executor() {
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
while (!d.isDisposed()) {
Thread.sleep(1);
}
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method runnableDisposedAsyncTimed2.
@Test(timeout = 1000)
public void runnableDisposedAsyncTimed2() throws Exception {
ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
try {
final Scheduler s = Schedulers.from(executorScheduler);
Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
while (!d.isDisposed()) {
Thread.sleep(1);
}
} finally {
executorScheduler.shutdownNow();
}
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method runnableDisposedAsyncCrash.
@Test(timeout = 1000)
public void runnableDisposedAsyncCrash() throws Exception {
final Scheduler s = Schedulers.from(new Executor() {
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
Disposable d = s.scheduleDirect(new Runnable() {
@Override
public void run() {
throw new IllegalStateException();
}
});
while (!d.isDisposed()) {
Thread.sleep(1);
}
}
use of io.reactivex.disposables.Disposable 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.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.
the class PaginationFragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
Disposable d2 = _paginator.onBackpressureDrop().concatMap(nextPage -> _itemsFromNetworkCall(nextPage + 1, 10)).observeOn(AndroidSchedulers.mainThread()).map(items -> {
int start = _adapter.getItemCount() - 1;
_adapter.addItems(items);
_adapter.notifyItemRangeInserted(start, 10);
_progressBar.setVisibility(View.INVISIBLE);
return items;
}).subscribe();
// I'm using an Rxbus purely to hear from a nested button click
// we don't really need Rx for this part. it's just easy ¯\_(ツ)_/¯
Disposable d1 = _bus.asFlowable().subscribe(event -> {
if (event instanceof PaginationAdapter.ItemBtnViewHolder.PageEvent) {
int nextPage = _adapter.getItemCount() - 1;
_paginator.onNext(nextPage);
}
});
_disposables.add(d1);
_disposables.add(d2);
}
Aggregations