![](/img/trans.png)
[英]Rx take first element and skip following elements for an interval of time
[英]Rx how to take first n elements of a sequence within time interval and ignore others
我在程序中使用Rx,并希望创建可观察的订阅,该订阅在一分钟的时间间隔内需要5个第一元素,而忽略其他元素。 例如,
Sequence: -1---2--3--4-5---6---7-8--------------
Interval: |------------------|------------------|
Result: |1---2--3--4-5-----|-7-8--------------|
有什么想法吗? 提前致谢
在这种情况下, Window
+ SelectMany
+ Take
将起作用:
var subscription = source.Window(TimeSpan.FromMinutes(1))
.SelectMany(w => w.Take(5))
.Subscribe(item => Console.WriteLine(item));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.