簡體   English   中英

接收如何在時間間隔內取序列的前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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM