iAsyncencencentering和节流
消耗iaSyncenncenumerable< t>
时是否可以防风数据? 我有一系列数据流很快,我只对每n秒钟的最后一个元素感兴趣。
谢谢。
Is it possible to throttle the data when consuming IAsyncEnumerable<T>
?
I have a stream of data coming in rapidly, and I'm only interested in the last element every N seconds.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
拥有一个不同的端点似乎是有意义的,该端点返回最近的事件,而不是处理流。
如果您必须处理队列/流,则可以食用这些事件,并将每个新的传入分配给
最新
之类的东西,并按照所需的间隔阅读。It would seem to make sense to have a different endpoint which returns the most recent event rather than a dealing with the stream.
If you have to deal with a queue/stream you could consume the events and assign each new incoming one to something like
latest
and read that at the desired interval.一种解决方案是将
IASYNCENUMEASS转换为
iobservable&lt; t&gt;
,并利用system.systems.reeactive
首先,您需要一个转换器。我找不到内置,所以我
使用此转换器创建了自己的创建,您可以使用
myEnumerable.toObservable()
,并使用示例
用于从system节流的方法。反应性
One solution is to convert
IAsyncEnumerable<T>
toIObservable<T>
and leverage power ofSystem.Reactive
First, you need a converter. I couldn't find builtin so I've created my own
With this converter you can use
myEnumerable.ToObservable()
and useSample
method for throttling fromSystem.Reactive