Rx java RxJava-blockingGet()方法在使用mergeWith运算符时停止线程

Rx java RxJava-blockingGet()方法在使用mergeWith运算符时停止线程,rx-java,blocking,rx-java2,Rx Java,Blocking,Rx Java2,我有一个用例,我需要一个反馈循环,它将根据某些条件从已经发出的项中发出一个项 示例代码: Flowable<Integer> range1 = Flowable.range(1, 10); UnicastProcessor<Integer> publishProcessor = UnicastProcessor.create(); Single<List<Integer>> pollResponse = range1

我有一个用例,我需要一个反馈循环,它将根据某些条件从已经发出的项中发出一个项

示例代码:

    Flowable<Integer> range1 = Flowable.range(1, 10);
    UnicastProcessor<Integer> publishProcessor = UnicastProcessor.create();

    Single<List<Integer>> pollResponse =  range1
            .mergeWith(publishProcessor) //On Commenting this line code works without wanted behaviour
            .map(integer -> {
                if (integer % 2 == 0 && integer <= 10) {
                    publishProcessor.onNext(20 + integer);
                }
                return integer;
            })
            .flatMap(integer -> flatMapMock(integer, publishProcessor))
            .toList()
            .doOnError(throwable -> System.out.println(throwable));

    List<Integer> integers = pollResponse.blockingGet();
    System.out.println(integers.size());
可流动范围1=可流动范围(1,10);
UnicastProcessor publishProcessor=UnicastProcessor.create();
单个pollResponse=range1
.mergeWith(publishProcessor)//在注释这行代码时,没有需要的行为
.map(整数->{
if(整数%2==0&&integer flatMapMock(整数,publishProcessor))
托利斯先生()
.doOnError(可丢弃->系统输出.println(可丢弃));
List integers=pollResponse.blockingGet();
System.out.println(integers.size());
flatMapMock函数:

private static Flowable<Integer> flatMapMock(Integer integer, 
    FlowableProcessor<Integer> feedbackSource){

    return Flowable.just(integer)
            .map(integer1 -> integer1);
}
私有静态可流动flatMapMock(整数,
可流动处理器(反馈源){
返回可流动的.just(整数)
.map(integer1->integer1);
}
我的问题是:

  • 如果我没有将publishProcessor与range1 flowable合并,那么我 我一直到打印列表大小。但是,关于合并,为什么不 它起作用了吗?
  • 我这里漏了什么吗?任何指针都可以

问题在于,您使用的是需要有限流的
toList
,但是您在
UnicastProcessor
中进行合并,该处理器从未完成,因此
mergeWith
从未完成。您可能应该重新思考您想要实现的目标