Get next event in sequence every second with reactive-extensions

前端 未结 3 1105
再見小時候
再見小時候 2021-01-20 16:08

I have the below types ...

public class NewsFeed
{
    public event EventHandler NewItem;

    .....

}

public class NewsItemEventA         


        
3条回答
  •  执念已碎
    2021-01-20 16:35

    I couldn't get the answer from Asti to work. So I tried the undocumented Delay overload with the delayDurationSelector. I got it working for my problem, though somehow it's not behaving correctly when I use the scheduler in the timer, but it works without it:

    public static IObservable DelayBetweenValues(this IObservable observable, TimeSpan interval,
        IScheduler scheduler)
    {
            var offset =  TimeSpan.Zero;
            return observable
                .TimeInterval(scheduler)
                .Delay(ti =>
                {
                    offset = (ti.Interval < interval) ? offset.Add(interval) : TimeSpan.Zero;
                    return Observable.Timer(offset);
                })
                .Select(ti => ti.Value);
    }
    

提交回复
热议问题