Using Rx, take the last fired event every 60 seconds

c#, events, system.reactive

Solution

I think this is being over engineered, you just need to use `Sample`, it does exactly what you want:

source.Sample(TimeSpan.FromSeconds(60)).Subscribe(x => /* .. */);

Problem

I have an event that fires (potentially) every second (a timer tick). What I'd like to do is take the last tick's `EventArgs` value every 60 seconds (if there were new ticks during those 60 seconds). I tried doing something like: ``` Observable.FromEventPattern( h => myThing.SomeEvent += h, h => myThing.SomeEvent -= h) .Throttle(TimeSpan.FromSeconds(60)) .TakeLast(1) .Do(p => // do something with p); ``` Unfortunately I never get to the `Do` method, and I'm not sure what I'm doing wrong? Apologies if this is completely wrong, my first time using Rx :) Edit: Per suggestions below, I changed `Do` to `Subscribe`, but I still don't get any results, if I use `Throttle`. Should I be using it at all?

Original source