io.reactivex.Single.merge()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(146)

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

Single.merge介绍

[英]Flattens a Single that emits a Single into a single Single that emits the item emitted by the nested Single, without any transformation.

Scheduler: merge does not operate by default on a particular Scheduler. The resulting Single emits the outer source's or the inner SingleSource's Throwable as is. Unlike the other merge() operators, this operator won't and can't produce a CompositeException because there is only one possibility for the outer or the inner SingleSource to emit an onError signal. Therefore, there is no need for a mergeDelayError(SingleSource>) operator.
[中]将发射单体的单体展平为发射嵌套单体发射的项目的单体,而不进行任何转换。
计划程序:默认情况下,合并不会在特定计划程序上运行。由此产生的单发照原样发射外部源或内部源的可丢弃信号。与其他merge()运算符不同,此运算符不会也不能生成CompositeException,因为外部或内部单一源只有一种可能发出onError信号。因此,不需要mergeDelayError(SingleSource>)运算符。

代码示例

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

@Test(expected = NullPointerException.class)
public void mergeSingleNull() {
  Single.merge((Single<Single<Integer>>)null);
}

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

@Test(expected = NullPointerException.class)
public void mergeIterableNull() {
  Single.merge((Iterable<Single<Integer>>)null);
}

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

@SuppressWarnings("unchecked")
@Test(expected = NullPointerException.class)
public void mergeIterableOneIsNull() {
  Single.merge(Arrays.asList(null, just1)).blockingSubscribe();
}

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

/**
 * Flattens this and another Single into a single Flowable, without any transformation.
 * <p>
 * <img width="640" height="415" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.mergeWith.png" alt="">
 * <p>
 * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
 * the {@code mergeWith} method.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code mergeWith} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param other
 *            a SingleSource to be merged
 * @return  that emits all of the items emitted by the source Singles
 * @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> mergeWith(SingleSource<? extends T> other) {
  return merge(this, other);
}

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

@Test(expected = NullPointerException.class)
public void mergeIterableIteratorNull() {
  Single.merge(new Iterable<Single<Object>>() {
    @Override
    public Iterator<Single<Object>> iterator() {
      return null;
    }
  }).blockingSubscribe();
}

代码示例来源:origin: redisson/redisson

/**
 * Flattens this and another Single into a single Flowable, without any transformation.
 * <p>
 * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.merge.png" alt="">
 * <p>
 * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
 * the {@code mergeWith} method.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code mergeWith} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param other
 *            a SingleSource to be merged
 * @return  that emits all of the items emitted by the source Singles
 * @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> mergeWith(SingleSource<? extends T> other) {
  return merge(this, other);
}

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

@SchedulerSupport(SchedulerSupport.NONE)
public static <T> Flowable<T> merge(Iterable<? extends SingleSource<? extends T>> sources) {
  return merge(Flowable.fromIterable(sources));

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

@Test
public void testMerge() {
  TestSubscriber<String> ts = new TestSubscriber<String>();
  Single<String> a = Single.just("A");
  Single<String> b = Single.just("B");
  Single.merge(a, b).subscribe(ts);
  ts.assertValueSequence(Arrays.asList("A", "B"));
}

代码示例来源:origin: redisson/redisson

@SchedulerSupport(SchedulerSupport.NONE)
public static <T> Flowable<T> merge(Iterable<? extends SingleSource<? extends T>> sources) {
  return merge(Flowable.fromIterable(sources));

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

@Test
public void merge2() {
  Single.merge(Single.just(1), Single.just(2))
  .test()
  .assertResult(1, 2);
}

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

@Test
public void mergeSingleSingle() {
  Single.merge(Single.just(Single.just(1)))
  .test()
  .assertResult(1);
}

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

@Test
public void merge3() {
  Single.merge(Single.just(1), Single.just(2), Single.just(3))
  .test()
  .assertResult(1, 2, 3);
}

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

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return merge(Flowable.fromArray(source1, source2));

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

@Test
public void mergeErrors() {
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    Single<Integer> source1 = Single.error(new TestException("First"));
    Single<Integer> source2 = Single.error(new TestException("Second"));
    Single.merge(source1, source2)
    .test()
    .assertFailureAndMessage(TestException.class, "First");
    assertTrue(errors.toString(), errors.isEmpty());
  } finally {
    RxJavaPlugins.reset();
  }
}

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

ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return merge(Flowable.fromArray(source1, source2, source3));

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

@Test
public void merge4() {
  Single.merge(Single.just(1), Single.just(2), Single.just(3), Single.just(4))
  .test()
  .assertResult(1, 2, 3, 4);
}

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return merge(Flowable.fromArray(source1, source2));

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

ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return merge(Flowable.fromArray(source1, source2, source3, source4));

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return merge(Flowable.fromArray(source1, source2, source3));

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return merge(Flowable.fromArray(source1, source2, source3, source4));

相关文章

微信公众号

最新文章

更多