io.reactivex.Flowable.as()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中io.reactivex.Flowable.as()方法的一些代码示例,展示了Flowable.as()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.as()方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:as

Flowable.as介绍

[英]Calls the specified converter function during assembly time and returns its resulting value.

This allows fluent conversion to any other type. Backpressure: The backpressure behavior depends on what happens in the converter function. Scheduler: as does not operate by default on a particular Scheduler.
[中]在汇编期间调用指定的转换器函数并返回其结果值。
这允许流畅地转换为任何其他类型。背压:背压行为取决于转换器功能中发生的情况。调度程序:默认情况下,as不会在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = NullPointerException.class)
public void asNull() {
  just1.as(null);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void flowableGenericsSignatureTest() {
  A<String, Integer> a = new A<String, Integer>() { };
  Flowable.just(a).as((FlowableConverter)ConverterTest.<String>testFlowableConverterCreator());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAsExtend() {
  final TestSubscriber<Object> subscriber = new TestSubscriber<Object>();
  final Object value = new Object();
  Object returned = Flowable.just(value).as(new FlowableConverter<Object, Object>() {
    @Override
    public Object apply(Flowable<Object> onSubscribe) {
        onSubscribe.subscribe(subscriber);
        subscriber.assertNoErrors();
        subscriber.assertComplete();
        subscriber.assertValue(value);
        return subscriber.values().get(0);
      }
  });
  assertSame(returned, value);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void as() {
  Flowable.just(1).as(new FlowableConverter<Integer, Observable<Integer>>() {
    @Override
    public Observable<Integer> apply(Flowable<Integer> v) {
      return v.toObservable();
    }
  })
  .test()
  .assertResult(1);
}

代码示例来源:origin: iMeiji/Toutiao

private void startIndicatorObserver() {
  Flowable.interval(1, 1, TimeUnit.SECONDS)
      .filter(aLong -> canHideFlag && System.currentTimeMillis() - mIndicatorHideTime > 1000)
      .subscribeOn(Schedulers.single())
      .observeOn(AndroidSchedulers.mainThread())
      .as(this.bindAutoDispose())
      .subscribe(new Consumer<Long>() {
        @Override
        public void accept(Long aLong) {
          canHideFlag = false;
          mIndicator.animate()
              .translationY(mIndicator.getHeight())
              .setDuration(400)
              .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                  super.onAnimationEnd(animation);
                  mIndicator.setVisibility(View.GONE);
                }
              });
        }
      });
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void flowableConverterThrows() {
  try {
    Flowable.just(1).as(new FlowableConverter<Integer, Integer>() {
      @Override
      public Integer apply(Flowable<Integer> v) {
        throw new TestException("Forced failure");
      }
    });
    fail("Should have thrown!");
  } catch (TestException ex) {
    assertEquals("Forced failure", ex.getMessage());
  }
}

代码示例来源:origin: uber/AutoDispose

@Test public void verifySubscriberDelegate() {
 final AtomicReference<Subscriber> atomicSubscriber = new AtomicReference<>();
 final AtomicReference<Subscriber> atomicAutoDisposingSubscriber = new AtomicReference<>();
 try {
  RxJavaPlugins.setOnFlowableSubscribe((source, subscriber) -> {
   if (atomicSubscriber.get() == null) {
    System.out.println(subscriber.getClass()
      .toString());
    atomicSubscriber.set(subscriber);
   } else if (atomicAutoDisposingSubscriber.get() == null) {
    System.out.println(subscriber.getClass()
      .toString());
    atomicAutoDisposingSubscriber.set(subscriber);
    RxJavaPlugins.setOnFlowableSubscribe(null);
   }
   return subscriber;
  });
  Flowable.just(1)
    .as(autoDisposable(ScopeProvider.UNBOUND))
    .subscribe();
  assertThat(atomicAutoDisposingSubscriber.get()).isNotNull();
  assertThat(atomicAutoDisposingSubscriber.get()).isInstanceOf(AutoDisposingSubscriber.class);
  assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()).delegateSubscriber()).isNotNull();
  assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()).delegateSubscriber()).isSameAs(
    atomicSubscriber.get());
 } finally {
  RxJavaPlugins.reset();
 }
}

代码示例来源:origin: uber/AutoDispose

@Test public void autoDispose_withProvider_withoutStartingLifecycle_shouldFail() {
 BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
 LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
 TestSubscriber<Integer> o = Flowable.just(1)
   .as(autoDisposable(provider))
   .test();
 List<Throwable> errors = o.errors();
 assertThat(errors).hasSize(1);
 assertThat(errors.get(0)).isInstanceOf(LifecycleNotStartedException.class);
}

代码示例来源:origin: uber/AutoDispose

@Test public void autoDispose_withSuperClassGenerics_compilesFine() {
 Flowable.just(new BClass())
   .as(autoDisposable(ScopeProvider.UNBOUND))
   .subscribe((Consumer<AClass>) aClass -> {
   });
}

代码示例来源:origin: uber/AutoDispose

@Test public void verifyCancellation() {
 final AtomicInteger i = new AtomicInteger();
 //noinspection unchecked because Java
 final FlowableEmitter<Integer>[] emitter = new FlowableEmitter[1];
 Flowable<Integer> source = Flowable.create(e -> {
  e.setCancellable(i::incrementAndGet);
  emitter[0] = e;
 }, BackpressureStrategy.LATEST);
 CompletableSubject scope = CompletableSubject.create();
 source.as(autoDisposable(scope))
   .subscribe();
 assertThat(i.get()).isEqualTo(0);
 assertThat(scope.hasObservers()).isTrue();
 emitter[0].onNext(1);
 scope.onComplete();
 emitter[0].onNext(2);
 // Verify cancellation was called
 assertThat(i.get()).isEqualTo(1);
 assertThat(scope.hasObservers()).isFalse();
}

代码示例来源:origin: uber/AutoDispose

@Test public void autoDispose_withProvider_afterLifecycle_shouldFail() {
 BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
 lifecycle.onNext(1);
 lifecycle.onNext(2);
 lifecycle.onNext(3);
 LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
 TestSubscriber<Integer> o = Flowable.just(1)
   .as(autoDisposable(provider))
   .test();
 List<Throwable> errors = o.errors();
 assertThat(errors).hasSize(1);
 assertThat(errors.get(0)).isInstanceOf(LifecycleEndedException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void compositeTest() {
  CompositeConverter converter = new CompositeConverter();
  Flowable.just(1)
      .as(converter)
      .test()
      .assertValue(1);
  Observable.just(1)
      .as(converter)
      .test()
      .assertValue(1);
  Maybe.just(1)
      .as(converter)
      .test()
      .assertValue(1);
  Single.just(1)
      .as(converter)
      .test()
      .assertValue(1);
  Completable.complete()
      .as(converter)
      .test()
      .assertComplete();
  Flowable.just(1)
  .parallel()
  .as(converter)
  .test()
  .assertValue(1);
}

代码示例来源:origin: RookieExaminer/MvpDemo

@Override
  public void login(String username, String password) {
    //View是否绑定 如果没有绑定,就不执行网络请求
    if (!isViewAttached()) {
      return;
    }
    mView.showLoading();
    model.login(username, password)
        .compose(RxScheduler.<BaseObjectBean<LoginBean>>Flo_io_main())
        .as(mView.<BaseObjectBean<LoginBean>>bindAutoDispose())
        .subscribe(new Consumer<BaseObjectBean<LoginBean>>() {
          @Override
          public void accept(BaseObjectBean<LoginBean> bean) throws Exception {
            mView.onSuccess(bean);
            mView.hideLoading();
          }
        }, new Consumer<Throwable>() {
          @Override
          public void accept(Throwable throwable) throws Exception {
            mView.onError(throwable);
            mView.hideLoading();
          }
        });
  }
}

代码示例来源:origin: hzsweers/blackmirror

.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.from(Looper.getMainLooper(), true))
.as(AutoDispose.<String>autoDisposable(AndroidLifecycleScopeProvider.from(this)))
.subscribe(new DisposableSubscriber<String>() {
 @Override public void onNext(String newLog) {

相关文章

Flowable类方法