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

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

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

Flowable.concatWith介绍

[英]Returns a Flowable that emits items from this Flowable and when it completes normally, the other CompletableSource is subscribed to and the returned Flowable emits its terminal events.

Backpressure: The operator does not interfere with backpressure between the current Flowable and the downstream consumer (i.e., acts as pass-through). When the operator switches to the Completable, backpressure is no longer present because Completable doesn't have items to apply backpressure to. Scheduler: concatWith does not operate by default on a particular Scheduler.
[中]返回一个从该流表中发出项的流表,当它正常完成时,订阅另一个CompletableSource,返回的流表发出其终端事件。
背压:操作员不会干扰可流动电流和下游耗电元件之间的背压(即,作为直通)。当操作员切换到Completable时,背压不再存在,因为Completable没有可应用背压的项目。调度程序:默认情况下,concatWith不会在特定调度程序上运行。

代码示例

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

  1. @Override
  2. public Publisher<Integer> createPublisher(long elements) {
  3. return
  4. Flowable.range(1, Math.max(0, (int)elements - 1))
  5. .concatWith(Single.just((int)elements))
  6. ;
  7. }
  8. }

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

  1. @Override
  2. public Flowable<String> apply(Resource resource) {
  3. return Flowable.fromArray(resource.getTextFromWeb().split(" "))
  4. .concatWith(Flowable.<String>error(new RuntimeException()));
  5. }
  6. };

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

  1. @Test
  2. public void skipLastTimedCustomSchedulerDelayError() {
  3. Flowable.just(1).concatWith(Flowable.just(2).delay(500, TimeUnit.MILLISECONDS))
  4. .skipLast(300, TimeUnit.MILLISECONDS, Schedulers.io(), true)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1);
  8. }

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

  1. @Test
  2. public void normal() {
  3. final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(1, 5)
  5. .concatWith(Single.just(100))
  6. .subscribe(ts);
  7. ts.assertResult(1, 2, 3, 4, 5, 100);
  8. }

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

  1. @Test
  2. public void normalNonDelayErrorOuter() {
  3. Flowable.range(1, 10).concatWith(Flowable.<Integer>error(new TestException()))
  4. .flatMapCompletable(new Function<Integer, CompletableSource>() {
  5. @Override
  6. public CompletableSource apply(Integer v) throws Exception {
  7. return Completable.complete();
  8. }
  9. }, false, Integer.MAX_VALUE)
  10. .test()
  11. .assertFailure(TestException.class);
  12. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void concatIterableDelayErrorWithError() {
  4. Flowable.concatDelayError(
  5. Arrays.asList(Flowable.just(1), Flowable.just(2),
  6. Flowable.just(3).concatWith(Flowable.<Integer>error(new TestException())),
  7. Flowable.just(4)))
  8. .test()
  9. .assertFailure(TestException.class, 1, 2, 3, 4);
  10. }

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

  1. @Test
  2. public void skipLastTimedDefaultScheduler() {
  3. Flowable.just(1).concatWith(Flowable.just(2).delay(500, TimeUnit.MILLISECONDS))
  4. .skipLast(300, TimeUnit.MILLISECONDS)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1);
  8. }

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

  1. @Test
  2. public void delayWithTimeDelayError() throws Exception {
  3. Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException()))
  4. .delay(100, TimeUnit.MILLISECONDS, true)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertFailure(TestException.class, 1);
  8. }

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

  1. @Test
  2. public void mergeDelayError3WithError() {
  3. Flowable.mergeDelayError(
  4. Flowable.just(1),
  5. Flowable.just(2).concatWith(Flowable.<Integer>error(new TestException())),
  6. Flowable.just(3)
  7. )
  8. .test()
  9. .assertFailure(TestException.class, 1, 2, 3);
  10. }

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

  1. @Test
  2. public void delayError() {
  3. TestSubscriber<Integer> ts = Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException()))
  4. .onBackpressureBuffer(true)
  5. .test(0L)
  6. .assertEmpty();
  7. ts.request(1);
  8. ts.assertFailure(TestException.class, 1);
  9. }

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

  1. @Test
  2. public void error() {
  3. new FlowablePublishMulticast<Integer, Integer>(Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())),
  4. Functions.<Flowable<Integer>>identity(), 16, true)
  5. .test()
  6. .assertFailure(TestException.class, 1);
  7. }

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

  1. @Test
  2. public void cancelOther() {
  3. CompletableSubject other = CompletableSubject.create();
  4. TestSubscriber<Object> ts = Flowable.empty()
  5. .concatWith(other)
  6. .test();
  7. assertTrue(other.hasObservers());
  8. ts.cancel();
  9. assertFalse(other.hasObservers());
  10. }

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

  1. @Test
  2. public void scalarAndRangeBackpressured() {
  3. TestSubscriber<Integer> ts = TestSubscriber.create(0);
  4. Flowable.just(1).concatWith(Flowable.range(2, 3)).subscribe(ts);
  5. ts.assertNoValues();
  6. ts.request(5);
  7. ts.assertValues(1, 2, 3, 4);
  8. ts.assertComplete();
  9. ts.assertNoErrors();
  10. }

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

  1. @Test
  2. public void rangeAndEmptyBackpressured() {
  3. TestSubscriber<Integer> ts = TestSubscriber.create(0);
  4. Flowable.range(1, 2).concatWith(Flowable.<Integer>empty()).subscribe(ts);
  5. ts.assertNoValues();
  6. ts.request(5);
  7. ts.assertValues(1, 2);
  8. ts.assertComplete();
  9. ts.assertNoErrors();
  10. }

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

  1. @Test
  2. public void emptyAndScalarBackpressured() {
  3. TestSubscriber<Integer> ts = TestSubscriber.create(0);
  4. Flowable.<Integer>empty().concatWith(Flowable.just(1)).subscribe(ts);
  5. ts.assertNoValues();
  6. ts.request(5);
  7. ts.assertValue(1);
  8. ts.assertComplete();
  9. ts.assertNoErrors();
  10. }

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

  1. @Test
  2. public void scalarAndEmptyBackpressured() {
  3. TestSubscriber<Integer> ts = TestSubscriber.create(0);
  4. Flowable.just(1).concatWith(Flowable.<Integer>empty()).subscribe(ts);
  5. ts.assertNoValues();
  6. ts.request(5);
  7. ts.assertValue(1);
  8. ts.assertComplete();
  9. ts.assertNoErrors();
  10. }

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

  1. @Test
  2. public void concatObservableDelayErrorWithError() {
  3. Flowable.concatDelayError(
  4. Flowable.just(Flowable.just(1), Flowable.just(2),
  5. Flowable.just(3).concatWith(Flowable.<Integer>error(new TestException())),
  6. Flowable.just(4)))
  7. .test()
  8. .assertFailure(TestException.class, 1, 2, 3, 4);
  9. }

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

  1. @Test
  2. public void concatObservableDelayErrorTillEnd() {
  3. Flowable.concatDelayError(
  4. Flowable.just(Flowable.just(1), Flowable.just(2),
  5. Flowable.just(3).concatWith(Flowable.<Integer>error(new TestException())),
  6. Flowable.just(4)), 2, true)
  7. .test()
  8. .assertFailure(TestException.class, 1, 2, 3, 4);
  9. }

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

  1. @Test
  2. public void testInnerBackpressureWithAlignedBoundaries() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(0, Flowable.bufferSize() * 2)
  5. .concatWith(Flowable.range(0, Flowable.bufferSize() * 2))
  6. .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer
  7. .subscribe(ts);
  8. ts.awaitTerminalEvent();
  9. ts.assertNoErrors();
  10. assertEquals(Flowable.bufferSize() * 4, ts.valueCount());
  11. }

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

  1. @Test
  2. public void observers() {
  3. PublishProcessor<Integer> pp = PublishProcessor.create();
  4. FlowableCache<Integer> cache = (FlowableCache<Integer>)Flowable.range(1, 5).concatWith(pp).cache();
  5. assertFalse(cache.hasSubscribers());
  6. assertEquals(0, cache.cachedEventCount());
  7. TestSubscriber<Integer> ts = cache.test();
  8. assertTrue(cache.hasSubscribers());
  9. assertEquals(5, cache.cachedEventCount());
  10. pp.onComplete();
  11. ts.assertResult(1, 2, 3, 4, 5);
  12. }

相关文章

Flowable类方法