use of io.reactivex.disposables.Disposable in project Varis-Android by dkhmelenko.
the class SearchResultsPresenter method startRepoSearch.
/**
* Starts repository search
*
* @param query Query string for search
*/
public void startRepoSearch(String query) {
Single<List<Repo>> reposSingle;
if (!TextUtils.isEmpty(query)) {
reposSingle = mTravisRestClient.getApiService().getRepos(query);
} else {
reposSingle = mTravisRestClient.getApiService().getRepos();
}
Disposable subscription = reposSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((repos, throwable) -> {
getView().hideProgress();
if (throwable == null) {
getView().setSearchResults(repos);
} else {
getView().showLoadingError(throwable.getMessage());
}
});
mSubscriptions.add(subscription);
}
use of io.reactivex.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.
the class PaginationAutoFragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
Disposable d2 = _paginator.onBackpressureDrop().doOnNext(i -> {
_requestUnderWay = true;
_progressBar.setVisibility(View.VISIBLE);
}).concatMap(this::_itemsFromNetworkCall).observeOn(AndroidSchedulers.mainThread()).map(items -> {
_adapter.addItems(items);
_adapter.notifyDataSetChanged();
return items;
}).doOnNext(i -> {
_requestUnderWay = false;
_progressBar.setVisibility(View.INVISIBLE);
}).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().filter(o -> !_requestUnderWay).subscribe(event -> {
if (event instanceof PaginationAutoAdapter.PageEvent) {
int nextPage = _adapter.getItemCount();
_paginator.onNext(nextPage);
}
});
_disposables.add(d1);
_disposables.add(d2);
_paginator.onNext(0);
}
use of io.reactivex.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.
the class PollingFragment method onStartSimplePollingClicked.
@OnClick(R.id.btn_start_simple_polling)
public void onStartSimplePollingClicked() {
final int pollCount = POLL_COUNT;
Disposable d = Flowable.interval(INITIAL_DELAY, POLLING_INTERVAL, TimeUnit.MILLISECONDS).map(this::_doNetworkCallAndGetStringResult).take(pollCount).doOnSubscribe(subscription -> {
_log(String.format("Start simple polling - %s", _counter));
}).subscribe(taskName -> {
_log(String.format(Locale.US, "Executing polled task [%s] now time : [xx:%02d]", taskName, _getSecondHand()));
});
_disposables.add(d);
}
use of io.reactivex.disposables.Disposable in project camel by apache.
the class BasicPublisherTest method testMultipleSubscriptions.
@Test
public void testMultipleSubscriptions() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:tick?period=50").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:unbounded");
}
}.addRoutesToCamelContext(context);
CountDownLatch latch1 = new CountDownLatch(5);
Disposable disp1 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch1.countDown());
context.start();
// Add another subscription
CountDownLatch latch2 = new CountDownLatch(5);
Disposable disp2 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch2.countDown());
assertTrue(latch1.await(5, TimeUnit.SECONDS));
assertTrue(latch2.await(5, TimeUnit.SECONDS));
// Unsubscribe both
disp1.dispose();
disp2.dispose();
// No active subscriptions, warnings expected
Thread.sleep(60);
// Add another subscription
CountDownLatch latch3 = new CountDownLatch(5);
Disposable disp3 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch3.countDown());
assertTrue(latch3.await(5, TimeUnit.SECONDS));
disp3.dispose();
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class SingleSubscribeOn method subscribeActual.
@Override
protected void subscribeActual(final SingleObserver<? super T> s) {
final SubscribeOnObserver<T> parent = new SubscribeOnObserver<T>(s, source);
s.onSubscribe(parent);
Disposable f = scheduler.scheduleDirect(parent);
parent.task.replace(f);
}
Aggregations