【问题标题】:RxJava's doOnSubscribe called after emit not beforeRxJava 的 doOnSubscribe 在发出之后而不是之前调用
【发布时间】:2020-02-25 10:05:47
【问题描述】:

我有一个看起来像这样的 RxJava 链:

Completable.complete()
    .andThen(fetchData())
    .andThen(fetchAnotherData())
    .andThen(...)
    .doOnSubscribe {
        /* some action */
    }

问题是 doOnSubscribe 回调中的代码在 last andThen() 之后调用。但我希望在获取任何数据之前调用它。如何实现?

【问题讨论】:

    标签: android kotlin rx-java2


    【解决方案1】:

    尝试defer订阅fetchData()完成

       Completable.complete()
                .andThen(Completable.defer { fetchData() })
                .andThen(Completable.defer { fetchAnotherData() })
                .doOnSubscribe { /* some action */ }
    

    【讨论】:

    猜你喜欢
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2015-03-02
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多