RxJava - .doAfterSubscribe()? [英] RxJava - .doAfterSubscribe()?

查看:39
本文介绍了RxJava - .doAfterSubscribe()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.doOnSubscribe() observable 的订阅者被附加之前执行.

.doOnSubscribe() is executed before an observable’s subscriber is attached.

我需要在附加订阅者之后 执行副作用.这可能吗?

I need to execute a side effect after the subscriber is attached. Is this possible?

推荐答案

在真正的工作"之前使用流的组合来执行一些事情:

Use composition of flows to perform something before the "real work":

Observable source = ... // the actual flow

source.startWith(
    Observable.empty()
    .doOnCompleted(() -> { /* your initial side-effect here */ })
)
.subscribe(/* consume the events of source */);

这篇关于RxJava - .doAfterSubscribe()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆