A simple Throttle class that can throttle a method with the signature Action<List<T>>
Includes a solution with a test project and the Throttle class
The content of this project itself is licensed under the Creative Commons Attribution 3.0 license, and the underlying source code used to format and display that content is licensed under the MIT license.
Action<List<int>> actionToBeThrottled = () => /* Do awesome stuff */;
var maximumElementsBeforeFlush = 100;
var automaticFlushTimeout = TimeSpan.FromMinutes(5);
var throttledAction = new Throttler<int>(actionToBeThrottled, maximumElementsBeforeFlush, automaticFlushTimeout);
// now, call the throttledAction
throttledAction.Call(new int());
throttledAction.Call(new List<int>(5));
// you can flush manually to...
throttledAction.Flush();
// if an exception occurs while calling the action, the OnError method is called
throttledAction.OnError = (exception, ints) =>
{
/* Example error handling
Log.Error("An error occurred while processing values", exception);
DoFallbackAction(ints);
*/
};