use of io.reactivex.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class SchedulerLifecycleTest method tryOutSchedulers.
private void tryOutSchedulers() throws InterruptedException {
final CountDownLatch cdl = new CountDownLatch(4);
final Runnable countAction = new Runnable() {
@Override
public void run() {
cdl.countDown();
}
};
CompositeDisposable csub = new CompositeDisposable();
try {
Worker w1 = Schedulers.computation().createWorker();
csub.add(w1);
w1.schedule(countAction);
Worker w2 = Schedulers.io().createWorker();
csub.add(w2);
w2.schedule(countAction);
Worker w3 = Schedulers.newThread().createWorker();
csub.add(w3);
w3.schedule(countAction);
Worker w4 = Schedulers.single().createWorker();
csub.add(w4);
w4.schedule(countAction);
if (!cdl.await(3, TimeUnit.SECONDS)) {
fail("countAction was not run by every worker");
}
} finally {
csub.dispose();
}
}
use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.
the class PollingFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_disposables = new CompositeDisposable();
}
use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.
the class RetrofitFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String githubToken = getResources().getString(R.string.github_oauth_token);
_githubService = GithubService.createGithubService(githubToken);
_disposables = new CompositeDisposable();
}
use of io.reactivex.disposables.CompositeDisposable 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);
}
use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.
the class RxBusDemo_Bottom3Fragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
//
_disposables.add(tapEventEmitter.subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
}));
_disposables.add(tapEventEmitter.publish(stream -> stream.buffer(stream.debounce(1, TimeUnit.SECONDS))).observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
_showTapCount(taps.size());
}));
_disposables.add(tapEventEmitter.connect());
}
Aggregations