In my win forms application I get data from web service periodically or on user request. It is required, that the web service is queried no more often than every 2 seconds, whereas the timer period is 5 seconds. At the startup the app should also get the data immediately.
IObservable<Timestamped<long>> timerObservable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(5))
.Timestamp();
IObservable<Timestamped<long>> buttonObservable = Observable.FromEvent(handler => button1.Click += handler, handler => button1.Click -= handler)
.Select(ev => 0L)
.Timestamp();
_subscription = timerObservable.Merge(buttonObservable)/*some code probably should be here*/
.Subscribe(l => Debug.WriteLine("send request to web service received at: " + DateTime.Now.TimeOfDay));
I can't achieve that with throttle, because it always delays sending the request. I tried also bufferWithTime like this:
.BufferWithTime(TimeSpan.FromSeconds(2))
.Where(l => l.Count > 0)
but it delays the startup. Any solution to that? I use RX 1.0 as the application is .NET 3.5 based.