简体   繁体   English

反应性扩展示例或节流?

[英]Reactive extensions Sample or Throttle?

I have a listBox and am observing when items are selected: 我有一个listBox,并观察何时选择项目:

selectedItems.Subscribe(DoWorkWIthSelectedItems);

The observable returns an array of viewModel items and in DoWorkWIthSelectedItems I go through the list of selected items and do some work. observable返回一个viewModel项的数组,在DoWorkWIthSelectedItems我浏览了所选项的列表并做了一些工作。 However, since the user may be spamming selections on/off pretty rapidly, whenever work is done on an item, I don't want any work to be done on that item again for 30 seconds. 但是,由于用户可能会非常快速地打开/关闭选择,每当对某个项目进行工作时,我都不希望再对该项目进行任何工作30秒。 After 30 seconds, if the item is selected again, go ahead and work on it. 30秒后,如果再次选择该项目,请继续操作。

Is there an Rx way to do this? 是否有Rx方式来做到这一点? I am not sure if it would be Sample or Throttle. 我不确定它是Sample还是Throttle。 Furthermore, I don't know if with Rx I am able to distinguish between items in the array that are good to be worked on or should be ignored. 此外,我不知道是否使用Rx我能够区分数组中的项目,这些项目可以用于处理或应该被忽略。 Would I need an additional property on the viewModel item to indicate some 'working' state? 我是否需要viewModel项上的附加属性来指示某些“工作”状态?

Thanks. 谢谢。

No matter what there's going to have to be some state. 不管有什么必须成为一个州。 I think your simplest solution would be something like (pseudocode) 我认为你最简单的解决方案就是(伪代码)

var recentlyUsed = new ConcurrentDictionary<T, DateTime>();
...
selectedItems
    .Do(/* remove expired items from recentlyUsed */)
    .Where(/* items are not in recently used */)
    .Do(/* add items to recently used */)
    .Subscribe(DoWorkWIthSelectedItems);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Reactive Extensions来限制客户端请求 - How to use Reactive Extensions to throttle client requests 限制/缓冲一个基于Reactive Extensions中的另一个Observable集合 - Throttle/Buffer one Observable collection based on another in Reactive Extensions 如何使用反应性扩展来缓存,限制和中继多个事件? - How to use Reactive Extensions to cache, throttle, and relay multiple events? 如何使用Reactive Extensions来限制SearchPane.SuggestionsRequested? - How can I use Reactive Extensions to throttle SearchPane.SuggestionsRequested? Xamarin.iOS的Reactive Extensions示例 - Reactive Extensions sample for Xamarin.iOS 将Sample(TimeSpan span)添加到Reactive Extensions管道会导致线程问题 - Adding Sample(TimeSpan span) to Reactive Extensions pipeline causes threading issues 如何组合IObservable <T> .Throttle()与其他一些使用Reactive Extensions的事件源? - How can I combine IObservable<T>.Throttle() with some other event source using Reactive Extensions? 如何使用Reactive Extensions使用最大窗口大小来限制事件? - How can I use Reactive Extensions to throttle Events using a max window size? Reactive.NET条件油门 - Reactive.NET Conditional Throttle 反应式(RX)油门无损失 - Reactive (RX) throttle without loss
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM