Reactive extension Timer/Interval reset

前端 未结 3 1746
不思量自难忘°
不思量自难忘° 2020-12-18 10:20

I have a project where I need to send a status message every 10 seconds unless there\'s been an update in the meantime. Meaning, every time there would be an update, the tim

3条回答
  •  伪装坚强ぢ
    2020-12-18 11:04

    I keep this little helper method with me:

    public static IObservable CreateAutoResetInterval(IObservable resetter, TimeSpan timeSpan, bool immediate = false)
    {
        return resetter.Select(_ => immediate ? Observable.Interval(timeSpan).StartWith(0) : Observable.Interval(timeSpan)).Switch();
    }
    

    It's basically the same mechanism as Enigmativity's answer

提交回复
热议问题