如何重新订阅特定点的序列?
我正在尝试解决以下问题: a) 订阅者在一段时间内接收来自 IObservable 的事件。然后它取消订阅,做一些事情然后再次订阅。在这里,它应该从执行取消订阅的同一点开始接收事件。 b) 这种行为对于多订阅者模型来说是理想的。例如,当一个人取消订阅时,其他人应该继续接收事件。
RX方面有什么建议吗?
提前致谢!
I'm trying to solve the following:
a) subscriber receives events from IObservable for some time. Then it unsubscribes, do some stuff and then subscribe again. Here it should start receiving events from exactly the same point where unsubscription was performed.
b) Such behavior is desirable for multiple subscribers model. E.g. when one has unsubscribed, others should continue receiving events.
Are there any suggestions from the RX side?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您需要一个“可暂停”流。假设一次只有 1 个订阅者会处理这些值(而其他订阅者只是等待),这个 解决方案可能就是您所需要的。
It sounds like you need a "pausable" stream. Assuming that only 1 subscriber will handle the values at a time (while the other subscribers just wait), this solution is probably what you need.
这是一种相当简单的 Rx 方法,可以执行您想要从 我的复制的操作回答 href="https://stackoverflow.com/questions/7620182/pause-and-resume-subscription-on-cold-iobservable">另一个问题。我创建了一个名为
Pausable
的扩展方法,它采用一个源 observable 和第二个 boolean 值的 observable,用于暂停或恢复该 observable。它可以这样使用:
Here's a reasonably simple Rx way to do what you want copied from my answer to this other question. I've created an extension method called
Pausable
that takes a source observable and a second observable of boolean that pauses or resumes the observable.It can be used like this: