Scheduling a IEnumerable periodically with .NET reactive extensions

后端 未结 5 573
闹比i
闹比i 2021-01-24 05:21

Say for example I have an enumerable

dim e = Enumerable.Range(0, 1024)

I\'d like to be able to do

dim o = e.ToObservable(Timesp         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 05:43

    I can only assume that you are using Range to dumb down your question.

    Do you want every value that the Enumerable pushes to be delayed by a second?

    var e = Enumerable.Range(0, 10);
    var o = Observable.Interval(TimeSpan.FromSeconds(1))
                      .Zip(e, (_,i)=>i);
    

    Or do you want only the last value of the Enumerable at each second to be pushed. i.e. reading from Enumerable that is evaluating as you enumerate it (perhaps some IO). In which case CombineLatest is more useful than Zip.

    Or perhaps you just want to get a value every second, in which case just use the Observable.Interval method

    var o = Observable.Interval(TimeSpan.FromSeconds(1));
    

    If you explain your problem space then the community will be able to better help you.

    Lee

    *Excuse the C# answer, but I dont know what the equivalent VB.NET code would be.

提交回复
热议问题