gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:29:45 25 4
gpt4 key购买 nike

我有一个接收 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com