I’ve got a large collection of simple pair class:
public class Pair { public DateTime Timestamp; public double Value; }
They are sorted by the ascending Timestamp. I want to trigger an event with the Value (say, Action<double>) for each item in the list at the appropriate time. The times are in the past, so I need to normalize the Timestamps such that the first one in the list is “now”. Can we set this up with the Reactive Extensions such that it triggers the next event after on the difference in time between two items?
Say
pairsis your sequence:Now
obsis pairs as an ordered observable.The zip takes care of turning the absolute times into offsets. It will take the sequence and join it with itself, but offset by one, as follows
This new value is then put into the
Observable.Timerto delay it the appropriate amount. The finalConcatflattens the result from anIObservable<IObservable<double>>into anIObservable<double>. This assumes that your sequence is ordered.