c# - 接收.NET : Take until specified count or timer elapsed

标签 c# linq system.reactive

我有一个接收 Observable 通知的解决方案,直到指定计数到达时间阈值过去。另外,我需要知道发生了什么。

想知道是否有更简单的方法(可能不是 GroupByUntil)来实现此功能

_values.
.GroupByUntil(_ => true,
              i => Observable.Timer(Threshold, _scheduler)
                             .Amb(i.Buffer(SpecifiedCount).Select(_ => SpecifiedCount)))
// this is for figuring out which one happened: interval elapsed or count filled
.SelectMany(g => g.Count())
// Let's say if count filled first, call Foo()
.Where( i => i == SpecifiedCount ) 
.Subscribe( _ => Foo() )

最佳答案

你在找Observable.Buffer Method (IObservable, TimeSpan, Int32)吗?根据文档

Indicates each element of an observable sequence into a buffer that’s sent out when either it’s full or a given amount of time has elapsed.

你应该能够写:

var myObservable=_values.Buffer(Threshold,SpecifiedCount);

Window 也有类似的重载

关于c# - 接收.NET : Take until specified count or timer elapsed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32735443/

相关文章:

c# - 当主线程终止时 SynchronizationContext 会发生什么?

c# - 使用 C# 将多个参数发布到 MVC Controller

c# - Linq - 带 IEnumerable<T> 的动态 GroupBy

c# - 用 Epplus 寻找值(value)

c# - 如何监控新上传文件的 FTP 传入文件夹?

c# - 如何检查 .NET (C#) 中的两个 GUID 是否匹配?

c# - WPF:装饰控件(文本框)隐藏时不隐藏 Validation.ErrorTemplate

c# - PLINQ 真的不保留顺序吗?

system.reactive - Rx 中的历史调度程序

c# - 复合可观察