use of rx.subjects.Subject in project AndroidNews by zhjohow.
the class RxBus method post.
/**
* 触发事件
*
* @param content
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void post(@NonNull Object tag, @NonNull Object content) {
LogUtils.logd("post" + "eventName: " + tag);
List<Subject> subjectList = subjectMapper.get(tag);
if (!isEmpty(subjectList)) {
for (Subject subject : subjectList) {
subject.onNext(content);
LogUtils.logd("onEvent" + "eventName: " + tag);
}
}
}
use of rx.subjects.Subject in project ribbon by Netflix.
the class HttpMetaRequest method convertToRibbonResponse.
private Observable<RibbonResponse<Observable<T>>> convertToRibbonResponse(final HystrixObservableCommandChain<T> commandChain, final Observable<ResultCommandPair<T>> hystrixNotificationObservable) {
return Observable.create(new OnSubscribe<RibbonResponse<Observable<T>>>() {
@Override
public void call(final Subscriber<? super RibbonResponse<Observable<T>>> t1) {
final Subject<T, T> subject = ReplaySubject.create();
hystrixNotificationObservable.materialize().subscribe(new Action1<Notification<ResultCommandPair<T>>>() {
AtomicBoolean first = new AtomicBoolean(true);
@Override
public void call(Notification<ResultCommandPair<T>> notification) {
if (first.compareAndSet(true, false)) {
HystrixObservableCommand<T> command = notification.isOnError() ? commandChain.getLastCommand() : notification.getValue().getCommand();
t1.onNext(new ResponseWithSubject<T>(subject, command));
t1.onCompleted();
}
if (notification.isOnNext()) {
subject.onNext(notification.getValue().getResult());
} else if (notification.isOnCompleted()) {
subject.onCompleted();
} else {
// onError
subject.onError(notification.getThrowable());
}
}
});
}
});
}
Aggregations