本文整理匯總了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));
}