How to throttle event stream using RX?

前端 未结 8 767
终归单人心
终归单人心 2020-11-27 04:04

I want to effectively throttle an event stream, so that my delegate is called when the first event is received but then not for 1 second if subsequent events are received. A

8条回答
  •  春和景丽
    2020-11-27 04:31

    Okay,

    you have 3 scenarios here:

    1) I would like to get one value of the event stream every second. means: that if it produces more events per second, you will get a always bigger buffer.

    observableStream.Throttle(timeSpan)
    

    2) I would like to get the latest event, that was produced before the second happens means: other events get dropped.

    observableStream.Sample(TimeSpan.FromSeconds(1))
    

    3) you would like to get all events, that happened in the last second. and that every second

    observableStream.BufferWithTime(timeSpan)
    

    4) you want to select what happens in between the second with all the values, till the second has passed, and your result is returned

    observableStream.CombineLatest(Observable.Interval(1000), selectorOnEachEvent)
    

提交回复
热议问题