【问题标题】:How to add andThen() in a Completable.complete() programmatically in Rx / Reactive Java如何在 Rx / Reactive Java 中以编程方式在 Completable.complete() 中添加 andThen()
【发布时间】:2022-10-14 02:07:05
【问题描述】:

如何在 Completable 上创建一系列 andThen() 运算符?

例如,原始代码是这样的:

return Completable.complete()
        .andThen(processdata("01"))
        .andThen(processdata("02"))
        .andThen(processdata("03"))
        .andThen(processdata("04"))
        .andThen(processdata("05"))
        .andThen(processdata("06"))
        .andThen(processdata("07")); //working

它工作得很好!

但我不想要一个“静态”定义的值,并试图将上面的代码转换为:

    Completable x = Completable.complete();
    String[] allID = {"01","02","09"}
    for (String Id : allID) {
        x.andThen(processdata(Id));
    }
    return x; //not working

它不工作,好像什么也没发生

然后我意识到:

        Completable x = Completable.complete();
        x.andThen(processdata("01"));
        x.andThen(processdata("02"));
        x.andThen(processdata("03"));
        return x; //not working

也不工作...

在我的情况下,任何人都可以帮助如何正确链接 Completable

【问题讨论】:

    标签: java reactive-programming rx-java2 reactive rx-java-completable


    【解决方案1】:

    尝试以这种方式链接Completable,因为每次调用andThen() 都会返回Completable 的新实例。

    Completable x = Completable.complete();
    String[] allID = {"01","02","09"}
    for (String Id : allID) {
      x = x.andThen(processdata(Id));
     }
    return x;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多