use of io.reactivex.disposables.CompositeDisposable in project Rocket.Chat.Android by RocketChat.
the class DDPClientImpl method ping.
public void ping(final TaskCompletionSource<DDPClientCallback.Ping> task, @Nullable final String id) {
final boolean requested = (TextUtils.isEmpty(id)) ? sendMessage("ping", null) : sendMessage("ping", json -> json.put("id", id));
if (requested) {
CompositeDisposable subscriptions = new CompositeDisposable();
subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message).map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString).map(DDPClientImpl::toJson).timeout(4, TimeUnit.SECONDS).subscribe(response -> {
String msg = extractMsg(response);
if ("pong".equals(msg)) {
if (response.isNull("id")) {
task.setResult(new DDPClientCallback.Ping(client, null));
subscriptions.dispose();
} else {
String _id = response.optString("id");
if (id.equals(_id)) {
task.setResult(new DDPClientCallback.Ping(client, id));
subscriptions.dispose();
}
}
}
}, err -> task.setError(new DDPClientCallback.Ping.Timeout(client))));
addErrorCallback(subscriptions, task);
} else {
task.trySetError(new DDPClientCallback.Closed(client));
}
}
use of io.reactivex.disposables.CompositeDisposable in project mosby by sockeqwe.
the class MviBasePresenter method bindIntentActually.
@MainThread
private <I> Observable<I> bindIntentActually(@NonNull V view, @NonNull IntentRelayBinderPair<?> relayBinderPair) {
if (view == null) {
throw new NullPointerException("View is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
if (relayBinderPair == null) {
throw new NullPointerException("IntentRelayBinderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
Subject<I> intentRelay = (Subject<I>) relayBinderPair.intentRelaySubject;
if (intentRelay == null) {
throw new NullPointerException("IntentRelay from binderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
ViewIntentBinder<V, I> intentBinder = (ViewIntentBinder<V, I>) relayBinderPair.intentBinder;
if (intentBinder == null) {
throw new NullPointerException(ViewIntentBinder.class.getSimpleName() + " is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
Observable<I> intent = intentBinder.bind(view);
if (intent == null) {
throw new NullPointerException("Intent Observable returned from Binder " + intentBinder + " is null");
}
if (intentDisposables == null) {
intentDisposables = new CompositeDisposable();
}
intentDisposables.add(intent.subscribeWith(new DisposableIntentObserver<I>(intentRelay)));
return intentRelay;
}
use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.
the class AestheticCheckBox method onAttachedToWindow.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
subscriptions = new CompositeDisposable();
// noinspection ConstantConditions
subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {
@Override
public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
invalidateColors(colorIsDarkState);
}
}, onErrorLogAndRethrow()));
subscriptions.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this)));
}
use of io.reactivex.disposables.CompositeDisposable in project DevRing by LJYcoder.
the class RxBus method register.
/**
* 注册事件监听
*
* @param object
*/
public void register(Object object) {
if (object == null) {
throw new NullPointerException("Object to register must not be null.");
}
CompositeDisposable compositeDisposable = new CompositeDisposable();
EventComposite subscriberMethods = EventFind.findAnnotatedSubscriberMethods(object, compositeDisposable);
mEventCompositeMap.put(object, subscriberMethods);
if (!STICKY_EVENT_MAP.isEmpty()) {
// 如果有粘性事件,则发送粘性事件
subscriberMethods.subscriberSticky(STICKY_EVENT_MAP);
}
}
Aggregations