【问题标题】:Ist it possible to combine arbitrarily many timed Flux into one?是否可以将任意多个定时 Flux 合并为一个?
【发布时间】:2018-09-05 10:02:50
【问题描述】:

我知道 combineLatest() 将最后一个值组合到两到六个 Flux 实例 (Combining Publishers in Project ) 中。但是,假设我有一个List<Flux<Integer>> listOfFlux。是否有可能将所有这些组合成一个,例如listOfFlux.combineAllLatest( (a,b) -> a + b) )?

【问题讨论】:

    标签: reactive-programming project-reactor


    【解决方案1】:

    是的,有一个专门的运算符变体:

    Flux.combineLatest(Iterable<? extends Publisher<? extends T>> sources,
                                              Function<Object[],V> combinator)
    

    你可以像这样使用它:

    List<Flux<Integer>> listOfFlux = //...
    Flux<Integer> result = Flux.combineLatest(listOfFlux, arr -> {
        //...
    });
    

    【讨论】:

    • 嗯,刚刚在我的代码中尝试过。但是这个例子也不起作用,因为 arr 是 Object[] 类型的,它没有 forEach 方法。
    • 是的,我可以通过将对象转换为其他类型来生成工作代码,但这不是类型安全的。你认为向 project-reactor 的人发送类型安全版本的请求是否有意义?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多