本文整理汇总了Java中io.reactivex.Flowable类的典型用法代码示例。如果您正苦于以下问题:Java Flowable类的具体用法?Java Flowable怎么用?Java Flowable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Flowable类属于io.reactivex包,在下文中一共展示了Flowable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldPresent_AnotherError_IntoView
import io.reactivex.Flowable; //导入依赖的package包/类
@Test public void shouldPresent_AnotherError_IntoView() throws Exception {
Flowable<FactAboutNumber> broken = Flowable.error(new IllegalAccessError("WTF!"));
when(usecase.fetchTrivia()).thenReturn(broken);
presenter.fetchRandomFacts();
BehavioursRobot.with(view)
.showLoadingFirstHideLoadingAfter()
.disableRefreshFirstAndEnableAfter()
.shouldShowErrorState()
.shouldNotShowEmptyState()
.shouldNotReportNetworkingError();
DataFlowWatcher.with(onNext, onError, onCompleted).shouldFinishWithError();
verify(strategist, oneTimeOnly()).applyStrategy(any());
}
示例2: getApiTransformer
import io.reactivex.Flowable; //导入依赖的package包/类
/**
* 异常处理变换
*
* @return
*/
public static <T extends IModel> FlowableTransformer<T, T> getApiTransformer() {
return new FlowableTransformer<T, T>() {
@Override
public Publisher<T> apply(Flowable<T> upstream) {
return upstream.flatMap(new Function<T, Publisher<T>>() {
@Override
public Publisher<T> apply(T model) throws Exception {
if (model == null || model.isNull()) {
return Flowable.error(new NetError(model.getErrorMsg(), NetError.NoDataError));
} else if (model.isAuthError()) {
return Flowable.error(new NetError(model.getErrorMsg(), NetError.AuthError));
} else if (model.isBizError()) {
return Flowable.error(new NetError(model.getErrorMsg(), NetError.BusinessError));
} else {
return Flowable.just(model);
}
}
});
}
};
}
示例3: computeStatistics
import io.reactivex.Flowable; //导入依赖的package包/类
@Transformation
public void computeStatistics() {
reviews
.transformPayloadFlow(flow ->
flow
.groupBy(data -> data.getString("course"))
.flatMap(group ->
group
.map(i -> i.getInteger("rating"))
.buffer(1, TimeUnit.MINUTES)
.map(Flowable::fromIterable)
.flatMap(MathFlowable::averageDouble)
.map(avg -> Pair.pair(group.getKey(), avg)
))
)
.to(Sink.forEachPayload(pair -> System.out.println("Window rating of " + pair.left() + " : " + pair.right())));
}
示例4: onCreate
import io.reactivex.Flowable; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLoginObservable = Observable
.timer(TIME_DELAY, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.map(aLong -> "User id is " + UUID.randomUUID().toString());
mLoginFlowable = Flowable
.timer(TIME_DELAY, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.map(aLong -> "User id is " + UUID.randomUUID().toString());
mCompositeDisposable = new CompositeDisposable();
findViewById(R.id.button_observable).setOnClickListener(this);
findViewById(R.id.button_flowable).setOnClickListener(this);
}
示例5: onCreate
import io.reactivex.Flowable; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose_operator_example);
/*
Compose for reusable code.
*/
Observable.just(1, 2, 3, 4, 5)
.compose(schedulers.<Integer>applyObservableAsync())
.subscribe(/* */);
Flowable.just(1, 2, 3, 4, 5)
.compose(schedulers.<Integer>applyFlowableAsysnc())
.subscribe(/* */);
}
示例6: bodyRespectsBackpressure
import io.reactivex.Flowable; //导入依赖的package包/类
@Test public void bodyRespectsBackpressure() {
server.enqueue(new MockResponse().setBody("Hi"));
RecordingSubscriber<String> subscriber = subscriberRule.createWithInitialRequest(0);
Flowable<String> o = service.body();
o.subscribe(subscriber);
assertThat(server.getRequestCount()).isEqualTo(1);
subscriber.assertNoEvents();
subscriber.request(1);
subscriber.assertAnyValue().assertComplete();
subscriber.request(Long.MAX_VALUE); // Subsequent requests do not trigger HTTP or notifications.
assertThat(server.getRequestCount()).isEqualTo(1);
}
示例7: zip
import io.reactivex.Flowable; //导入依赖的package包/类
@Test
public void zip() throws Exception{
Consumer<Object> consumer = v -> System.out.println("[" + System.currentTimeMillis() / 100 + "] " + v);
Flowable<Long> f1 = Flowable.interval(100, TimeUnit.MILLISECONDS);
Flowable<Long> f2 = Flowable.interval(200, TimeUnit.MILLISECONDS);
Flowable<Long> f3 = Flowable.zip(f1, f2, (x, y) -> x * 10000 + y);
f3.subscribe(consumer);
}
示例8: regPerson
import io.reactivex.Flowable; //导入依赖的package包/类
@POST("user/regist/person")
@Multipart
Flowable<ResponseDto<User>> regPerson(
@PartMap Map<String, RequestBody> param,
@Part MultipartBody.Part front,
@Part MultipartBody.Part back
);
示例9: from
import io.reactivex.Flowable; //导入依赖的package包/类
@Override
public <E> Flowable<RealmList<E>> from(Realm realm, final RealmList<E> list) {
final RealmConfiguration realmConfig = realm.getConfiguration();
return Flowable.create(new FlowableOnSubscribe<RealmList<E>>() {
@Override
public void subscribe(final FlowableEmitter<RealmList<E>> emitter) throws Exception {
// Gets instance to make sure that the Realm is open for as long as the
// Observable is subscribed to it.
final Realm observableRealm = Realm.getInstance(realmConfig);
listRefs.get().acquireReference(list);
final RealmChangeListener<RealmList<E>> listener = new RealmChangeListener<RealmList<E>>() {
@Override
public void onChange(RealmList<E> results) {
if (!emitter.isCancelled()) {
emitter.onNext(list);
}
}
};
list.addChangeListener(listener);
// Cleanup when stream is disposed
emitter.setDisposable(Disposables.fromRunnable(new Runnable() {
@Override
public void run() {
list.removeChangeListener(listener);
observableRealm.close();
listRefs.get().releaseReference(list);
}
}));
// Emit current value immediately
emitter.onNext(list);
}
}, BACK_PRESSURE_STRATEGY);
}
示例10: unregister
import io.reactivex.Flowable; //导入依赖的package包/类
/**
* 取消监听
* @param tag
* @param flowable
* @return
*/
@SuppressWarnings("rawtypes")
public RxBus unregister(@NonNull Object tag,
@NonNull Flowable<?> flowable) {
if (null == flowable)
return getInstance();
List<FlowableProcessor> processors = mProcessorMapper.get(tag);
if (null != processors) {
processors.remove((FlowableProcessor<?>) flowable);
if (isEmpty(processors)) {
mProcessorMapper.remove(tag);
}
}
return getInstance();
}
示例11: definedFlowable
import io.reactivex.Flowable; //导入依赖的package包/类
private void definedFlowable() {
Flowable.interval(1, TimeUnit.MICROSECONDS)
.onBackpressureDrop() //加上背压策略
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Long>() {
@Override
public void onSubscribe(Subscription s) {
Log.d(TAG, "onSubscribe");
mSubscription = s;
s.request(Long.MAX_VALUE);
}
@Override
public void onNext(Long aLong) {
Log.d(TAG, "onNext: " + aLong);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable t) {
Log.w(TAG, "onError: ", t);
}
@Override
public void onComplete() {
Log.d(TAG, "onComplete");
}
});
}
示例12: testFlowable
import io.reactivex.Flowable; //导入依赖的package包/类
@Test
public void testFlowable() throws Exception {
Iterator<Integer> iterator = Flowable.range(0, 10)
.to(RxIterator.flowableIterator());
int i = 0;
while (iterator.hasNext()) {
assertEquals(i++, iterator.next().intValue());
}
}
示例13: oneToMany
import io.reactivex.Flowable; //导入依赖的package包/类
@Test
public void oneToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloRespStream(Single.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp
.doOnNext(msg -> System.out.println(msg))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"))
.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
示例14: insert
import io.reactivex.Flowable; //导入依赖的package包/类
@Override
public Flowable<Optional<TestModel>> insert(TestModel item) {
if(shouldThrowError){
return Flowable.error(new Exception("insertSingle.error"));
}
return Flowable.just(Optional.wrap(item)).delay(1, TimeUnit.SECONDS);
}
示例15: on
import io.reactivex.Flowable; //导入依赖的package包/类
public <T> void on(String eventName, Consumer<T> consumer) {
Flowable<T> flowable = mRxBus.register(eventName);
mProcessorMap.put(eventName, flowable);
mDisposable.add(flowable.observeOn(AndroidSchedulers.mainThread())
.subscribe(consumer, throwable -> {
throwable.printStackTrace();
}));
}