返回当前状态加上更新 [英] Returning current state plus updates

查看:71
本文介绍了返回当前状态加上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道实现以下目标的最佳方式是: -

I'm wondering what the best way to achieve the following would be:-

我有一个对象使用正在填充数据的缓存(比如说一个字典< TKey,TValue>,它也接收更新并使缓存保持最新。我想在一个可观察的流中公开缓存和更新。我也想要在订阅时,
返回当前缓存的"初始图像"或"快照"。我正在考虑使用Publish和RefCount,因为这实际上是一个多播订阅,但我不确定如何返回"初始图像"。我想使用
StartsWith但我实际上想要返回一个值数组(即当前缓存TValue(s))而不是单个值。

I have an object with a cache that is being populated with data (lets say a Dictionary<TKey, TValue>, it is also receiving updates and keeping the cache up to date. I want to expose the cache and the updates in an observable stream. I also want to return an "initial image" or "snapshot" of the current cache when the subscription is made. I was thinking of using Publish and RefCount since this is essentially a multi-cast subscription but I'm not sure how to return the "initial image". I thought of using StartsWith but I actually want to return an array of values (i.e. the current cache TValue(s)) rather than a single value.

有什么想法?

推荐答案

您好,

您可以使用  DictionarySubject  
Rxx 。   订阅
实现返回现有快照,然后是实时更新。

You can use DictionarySubject in Rxx.  The Subscribe implementation returns an existing snapshot followed by live updates.

- 戴夫


这篇关于返回当前状态加上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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