How to throttle event stream using RX?

前端 未结 8 770
终归单人心
终归单人心 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:21

    Have you tried the Throttle extension method?

    From the docs:

    Ignores values from an observable sequence which are followed by another value before dueTime

    It's not quite clear to me whether that's going to do what you want or not - in that you want to ignore the following values rather than the first value... but I would expect it to be what you want. Give it a try :)

    EDIT: Hmmm... no, I don't think Throttle is the right thing, after all. I believe I see what you want to do, but I can't see anything in the framework to do it. I may well have missed something though. Have you asked on the Rx forum? It may well be that if it's not there now, they'd be happy to add it :)

    I suspect you could do it cunningly with SkipUntil and SelectMany somehow... but I think it should be in its own method.

提交回复
热议问题