Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

pitermarx/Throttler

Repository files navigation

A simple Throttle class that can throttle a method with the signature Action<List<T>>

Project Setup

Includes a solution with a test project and the Throttle class

License

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.

Example

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);
        */
    };

Build status

About

Throttler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages