使流保持活跃

时间:2018-06-28 16:19:36

标签: java kotlin rx-java rx-java2

有一个项目流(Observable),客户代码可以随时取消订阅。默认情况下,Disposable在客户端取消订阅并终止流时被处置。有没有办法让流保持鲜活?

默认方式:

val subscriber;
val disposable = Observable.concat(obs1, obs2, obs3).subscribe(subscriber);
//later
disposable.dispose();
//obs1 and obs2 are executed, but obs3 not

我在寻找什么

val subscriber;
val subscriberForDisposed;
val disposable = Observable.concat(obs1, obs2, obs3)
            .deliverIfDisposed(subscriberForDisposed)
            .subscribe(subscriber);
//later
disposable.dispose()
//obs1 and obs2 are executed and delivered to subscriber
//obs3 is executed and delivered to subscriberForDisposed

0 个答案:

没有答案