本文整理汇总了Java中io.reactivex.Observable.subscribeWith方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.subscribeWith方法的具体用法?Java Observable.subscribeWith怎么用?Java Observable.subscribeWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.subscribeWith方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> source =
Observable.interval(1, TimeUnit.SECONDS);
ResourceObserver<Long> myObserver = new
ResourceObserver<Long>() {
@Override
public void onNext(Long value) {
System.out.println(value);
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
System.out.println("Done!");
}
};
//capture Disposable
Disposable disposable = source.subscribeWith(myObserver);
}
示例2: test
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test public void test(){
Observable<Todo> todoObservable = Observable.create(new ObservableOnSubscribe<Todo>() {
@Override
public void subscribe(ObservableEmitter<Todo> emitter) throws Exception {
try {
List<Todo> todos = RxJavaUnitTest.this.getTodos();
if (todos!=null){
throw new NullPointerException("todos was null");
}
for (Todo todo : todos) {
emitter.onNext(todo);
}
emitter.onComplete();
} catch (Exception e) {
emitter.onError(e);
}
}
});
TestObserver<Object> testObserver = new TestObserver<>();
todoObservable.subscribeWith(testObserver);
testObserver.assertError(NullPointerException.class);
}
示例3: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
Observable<CacheResult<T>> observable = build().toObservable(generateRequest(), proxy);
if (CacheResult.class != proxy.getCallBack().getRawType()) {
return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
@Override
public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
return upstream.map(new CacheResultFunc<T>());
}
}).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
} else {
return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
}
}
示例4: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
Observable<CacheResult<T>> observable = build().toObservable(apiManager.get(url, params.urlParamsMap), proxy);
if (CacheResult.class != proxy.getCallBack().getRawType()) {
return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
@Override
public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
return upstream.map(new CacheResultFunc<T>());
}
}).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
} else {
return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
}
}
示例5: call
import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable call(Observable<T> observable, CallBackProxy<? extends ApiResult<T>, T> proxy) {
Observable<CacheResult<T>> cacheobservable = build().toObservable(observable, proxy);
if (CacheResult.class != proxy.getCallBack().getRawType()) {
return cacheobservable.compose(new ObservableTransformer<CacheResult<T>, T>() {
@Override
public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
return upstream.map(new CacheResultFunc<T>());
}
}).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
} else {
return cacheobservable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
}
}
示例6: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
Observable<CacheResult<T>> observable = build().toObservable(apiManager.put(url, params.urlParamsMap), proxy);
if (CacheResult.class != proxy.getCallBack().getRawType()) {
return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
@Override
public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
return upstream.map(new CacheResultFunc<T>());
}
}).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
} else {
return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
}
}
示例7: executeObserver
import io.reactivex.Observable; //导入方法依赖的package包/类
public void executeObserver(DisposableObserver<T> observer, int from, int limit) {
if (observer != null) {
final Observable<T> observable = createObservableUseCase(from, limit).subscribeOn(executorSchedule).observeOn(uiSchedule);
DisposableObserver disposableObserver = observable.subscribeWith(observer);
compositeDisposable.add(disposableObserver);
}
}
示例8: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* Executes the current use case.
*
* @param observer {@link DisposableObserver} which will be listening to the observable build
* by {@link #buildUseCaseObservable(Params)} ()} method.
* @param params Parameters (Optional) used to build/execute this use case.
*/
public Disposable execute(DisposableObserver<T> observer, Params params) {
Preconditions.checkNotNull(observer);
final Observable<T> observable = this.buildUseCaseObservable(params)
.subscribeOn(Schedulers.from(threadExecutor))
.observeOn(postExecutionThread.getScheduler());
return observable.subscribeWith(observer);
}
示例9: subscribeViewState
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* This method subscribes the Observable emitting {@code ViewState} over time to the passed
* consumer.
* <b>Do only invoke this method once! Typically in {@link #bindIntents()}</b>
* <p>
* Internally Mosby will hold some relays to ensure that no items emitted from the ViewState
* Observable will be lost while viewState is not attached nor that the subscriptions to
* viewState
* intents will cause memory leaks while viewState detached.
* </p>
*
* Typically this method is used in {@link #bindIntents()} like this:
* <pre><code>
* Observable<MyViewState> viewState = ... ;
* subscribeViewStateConsumerActually(viewState, new ViewStateConsumer() {
* @Override
* public void accept(MyView view, MyViewState viewState){
* view.render(viewState);
* }
* }
* </code></pre>
*
* @param viewStateObservable The Observable emitting new ViewState. Typically an intent {@link
* #intent(ViewIntentBinder)} causes the underlying business logic to do a change and eventually
* create a new ViewState.
* @param consumer {@link ViewStateConsumer} The consumer that will update ("render") the view.
*/
@MainThread protected void subscribeViewState(@NonNull Observable<VS> viewStateObservable,
@NonNull ViewStateConsumer<V, VS> consumer) {
if (subscribeViewStateMethodCalled) {
throw new IllegalStateException(
"subscribeViewState() method is only allowed to be called once");
}
subscribeViewStateMethodCalled = true;
if (viewStateObservable == null) {
throw new NullPointerException("ViewState Observable is null");
}
if (consumer == null) {
throw new NullPointerException("ViewStateBinder is null");
}
this.viewStateConsumer = consumer;
viewStateDisposable = viewStateObservable.subscribeWith(
new DisposableViewStateObserver<>(viewStateBehaviorSubject));
}