use of io.reactivex.disposables.CompositeDisposable in project Rocket.Chat.Android by RocketChat.
the class DDPClientImpl method sub.
public void sub(final TaskCompletionSource<DDPSubscription.Ready> task, String name, JSONArray params, String id) {
final boolean requested = sendMessage("sub", json -> json.put("id", id).put("name", name).put("params", params));
if (requested) {
CompositeDisposable subscriptions = new CompositeDisposable();
subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message).map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString).map(DDPClientImpl::toJson).subscribe(response -> {
String msg = extractMsg(response);
if ("ready".equals(msg) && !response.isNull("subs")) {
JSONArray ids = response.optJSONArray("subs");
for (int i = 0; i < ids.length(); i++) {
String _id = ids.optString(i);
if (id.equals(_id)) {
task.setResult(new DDPSubscription.Ready(client, id));
subscriptions.dispose();
break;
}
}
} else if ("nosub".equals(msg) && !response.isNull("id") && !response.isNull("error")) {
String _id = response.optString("id");
if (id.equals(_id)) {
task.setError(new DDPSubscription.NoSub.Error(client, id, response.optJSONObject("error")));
subscriptions.dispose();
}
}
}, err -> {
}));
addErrorCallback(subscriptions, task);
} else {
task.trySetError(new DDPClientCallback.Closed(client));
}
}
use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.
the class RxBusDemo_Bottom1Fragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
_disposables.add(_rxBus.asFlowable().subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
}));
}
use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.
the class RxBusDemo_Bottom2Fragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
Flowable<Object> tapEventEmitter = _rxBus.asFlowable().share();
_disposables.add(tapEventEmitter.subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
}));
Flowable<Object> debouncedEmitter = tapEventEmitter.debounce(1, TimeUnit.SECONDS);
Flowable<List<Object>> debouncedBufferEmitter = tapEventEmitter.buffer(debouncedEmitter);
_disposables.add(debouncedBufferEmitter.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
_showTapCount(taps.size());
}));
}
use of io.reactivex.disposables.CompositeDisposable 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.CompositeDisposable in project RxJava by ReactiveX.
the class CompletableMergeDelayErrorIterable method subscribeActual.
@Override
public void subscribeActual(final CompletableObserver s) {
final CompositeDisposable set = new CompositeDisposable();
s.onSubscribe(set);
Iterator<? extends CompletableSource> iterator;
try {
iterator = ObjectHelper.requireNonNull(sources.iterator(), "The source iterator returned is null");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
s.onError(e);
return;
}
final AtomicInteger wip = new AtomicInteger(1);
final AtomicThrowable error = new AtomicThrowable();
for (; ; ) {
if (set.isDisposed()) {
return;
}
boolean b;
try {
b = iterator.hasNext();
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
error.addThrowable(e);
break;
}
if (!b) {
break;
}
if (set.isDisposed()) {
return;
}
CompletableSource c;
try {
c = ObjectHelper.requireNonNull(iterator.next(), "The iterator returned a null CompletableSource");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
error.addThrowable(e);
break;
}
if (set.isDisposed()) {
return;
}
wip.getAndIncrement();
c.subscribe(new MergeInnerCompletableObserver(s, set, error, wip));
}
if (wip.decrementAndGet() == 0) {
Throwable ex = error.terminate();
if (ex == null) {
s.onComplete();
} else {
s.onError(ex);
}
}
}
Aggregations