I'm using Rx in my programm and want to create subscription for observable that takes 5 first elements within one minute time interval and ignores others. For example,
Sequence: -1---2--3--4-5---6---7-8--------------
Interval: |------------------|------------------|
Result: |1---2--3--4-5-----|-7-8--------------|
Any thoughts? Thanks in advance
Window
+ SelectMany
+ Take
would work in this case:
var subscription = source.Window(TimeSpan.FromMinutes(1))
.SelectMany(w => w.Take(5))
.Subscribe(item => Console.WriteLine(item));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.