RxJava2 Flowable concatWith(连接操作符)

本文主要介绍了RxJava2中的Flowable.concatWith操作符,用于连接两个Flowable序列。在打印完第一个Flowable的所有项后,才会开始处理第二个Flowable的项。测试用例表明,前后Flowable的项目类型必须一致,否则无法编译。此外,文章还提到了其他一些相关操作符,如delay、delaySubscription、switchIfEmpty、debounce、count、contains、concatMap、collect、cast和cache。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

concatWith(连接操作符)

1 concatWith接口

Flowable<T>concatWith(CompletableSource other)

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.

返回从此Flowable发出项目的Flowable,当它正常完成时,将订阅另一个CompletableSource,并返回Flowable发出其终端事件。

Flowable<T>concatWith(MaybeSource<? extends T> other)

Returns a Flowable that emits the items from this Flowable followed by the success item or terminal events of the other MaybeSource.

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 that emits the items from this Flowable followed by the success item or error event of the other SingleSource.

返回一个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等其他类型。

 

其他操作符

delay delaySubscription(辅助操作符)

delaySubscription(辅助操作符)

switchIfEmpty(条件操作符)

debounce(过滤操作符)去重复操作

count(统计操作符)

contains(条件操作符)

concatWith(连接操作符)

concatMap(变换操作符)

collect & collectInto

cast

cache

buffer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值