var x = Observable.Return(1)
.Do(_ => Console.WriteLine("creating"))
.Replay()
.RefCount();
x.Subscribe(); //first subscription
x.Subscribe(); //second subscription
结果:
creating
creating
此处支持“创建”只打印一次。
但是第一个订阅似乎在第二个订阅开始之前就被处理掉了,引用计数回到零并且重播断开连接。
那么在我们不知道我们的源将在多长时间内完成并且我们想要多次订阅它的情况下使用 RefCount 的正确方法是什么?