Rx如何在时间间隔内获取序列的前n个元素并忽略其他元素

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));