All the documentation I found about rx.net throttling does not cover the overload with a parameter Func<TSource, IObservable<TThrottle>> throttleDurationSelector. So all I have available are the XML-comments. This suggests, that throttleDurationSelector is called on every new element in the source sequence. The expected return value would be a IObservable<TThrottle>. (My understanding) This enables the possibility to change the throttle-delay on every new element. But, this understanding does not match the runtime experience I discover.
var s = new Subject<string>();
s.Throttle(_ => Observable.Return(TimeSpan.FromMilliseconds(500))) // for simplicity of this demo, always return the same delay
.Subscribe(_ => Console.WriteLine($"{DateTime.Now}.{DateTime.Now.Millisecond} event {_}"));
for (int i = 0; i < 5; i++)
s.OnNext("a");
Thread.Sleep(1000);
for (int i = 0; i < 5; i++)
s.OnNext("b");
Thread.Sleep(1000);
According to the previously mentioned understanding (which is obviously wrong), I'd have expected the following output.
10.02.2022 11:47:54.386 event a
10.02.2022 11:47:55.388 event b
Instead this output is generated. It seems that there is no throttling applied at all.
10.02.2022 11:46:49.431 event a
10.02.2022 11:46:49.432 event a
10.02.2022 11:46:49.432 event a
10.02.2022 11:46:49.432 event a
10.02.2022 11:46:49.432 event a
10.02.2022 11:46:50.448 event b
10.02.2022 11:46:50.448 event b
10.02.2022 11:46:50.448 event b
10.02.2022 11:46:50.448 event b
10.02.2022 11:46:50.449 event b
What is the purpose of this overload, if not dynamically changing the throttle-delay (which is what I need)?
Also, why the 'complicated' syntax of Func<TSource, IObservable<TThrottle>> throttleDurationSelector where a simpler parameter Func<TSource, TThrottle> throttleDurationSelector would be good enough?