当前位置: 首页>>代码示例>>Java>>正文


Java Flowable类代码示例

本文整理汇总了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());
    }
 
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:18,代码来源:FactsPresenterTests.java

示例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);
                    }
                }
            });
        }
    };
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:29,代码来源:XApi.java

示例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())));
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:18,代码来源:ReviewRecentRating.java

示例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);
}
 
开发者ID:tranngoclam,项目名称:rx-progress-dialog,代码行数:18,代码来源:MainActivity.java

示例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(/* */);

}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:18,代码来源:ComposeOperatorExampleActivity.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:FlowableTest.java

示例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);
}
 
开发者ID:RXTeams,项目名称:RxjavaExample,代码行数:10,代码来源:ExampleUnitTest.java

示例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
);
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:8,代码来源:RegService.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:RealmObservableFactory.java

示例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();
}
 
开发者ID:ynztlxdeai,项目名称:MVPtemplate,代码行数:21,代码来源:RxBus.java

示例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");
                }
            });
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:34,代码来源:MainActivity.java

示例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());
  }
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:10,代码来源:RxIteratorTest.java

示例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);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:16,代码来源:ServerErrorIntegrationTest.java

示例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);
}
 
开发者ID:playmoweb,项目名称:store2store,代码行数:8,代码来源:TestStore.java

示例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();
                                    }));
}
 
开发者ID:ynztlxdeai,项目名称:MVPtemplate,代码行数:9,代码来源:RxManager.java


注:本文中的io.reactivex.Flowable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。