concatWith(连接操作符)
1 concatWith接口
Flowable<T> |
concatWith(CompletableSource other) Returns a 返回从此Flowable发出项目的Flowable,当它正常完成时,将订阅另一个CompletableSource,并返回Flowable发出其终端事件。 |
Flowable<T> |
concatWith(MaybeSource<? extends T> other) Returns a |
Flowable<T> |
concatWith(Publisher<? extends T> other) Returns a Flowable that emits the items emitted from the current Publisher, then the next, one after the other, without interleaving them. 返回一个Flowable,它发出从当前发布者发出的项,然后是下一个,一个接一个地发出,发射过程中不会交错发送。 |
Flowable<T> |
concatWith(SingleSource<? extends T> other) Returns a 返回一个Flowable,它会发出自己的项,后跟另一个SingleSource的成功项或错误事件。 |
2 concatWith图解说明
这里使用了与静态操作符concat一样的图解,简单理解就是续接下一个Flowable
3 concatWith测试用例
测试代码
@Test
public void concatWith() {
System.out.println("######concatWith#####");
Flowable.just(3, 2, 4).concatWith(Flowable.just(100, 200))
.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
System.out.println("concatWith, value:" + integer);
}
});
}
测试结果
######concatWith#####
concatWith, value:3
concatWith, value:2
concatWith, value:4
concatWith, value:100
concatWith, value:200
4 concatWith测试用例说明
测试结果已经一目了然了,在打印出第concatWith前面的Flowable的所有项目后,紧接着开始打印续接的Flowable中的项目,在做测试的过程中发现前后的项目的类型姚波吃一一致,否者无法编译通过,前面是Integer后面也应该是,不能使String等其他类型。