Rx observable which publishes a value if certain timeout expires

前端 未结 2 1053
再見小時候
再見小時候 2021-01-06 07:25

I have a method that returns an observable. This observable should (if evetything is working right) publish a value each second. What I would like to do is have it publish

2条回答
  •  囚心锁ツ
    2021-01-06 08:01

    I think that the following should work. It uses Throttle which will wait until 30 seconds have passed with no input before sending anything. You can then merge this with your preexisting source to get your desired behaviour.

    var bad = source
        .Throttle(TimeSpan.FromSeconds(30))
        .Select(_ => "bad");
    
    var merged = source.Merge(bad);
    

提交回复
热议问题