Rate Limiting (debounce, throttle) for C# Portable Class Library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vs/RateLimiting/v15
RateLimiting
RateLimitingCoreConsoleExample
RateLimitingExample
.gitignore
.travis.yml
README.md
RateLimiting.sln
RateLimiting.userprefs

README.md

RateLimiting.NET Build Status Nuget version downloads

This library help you use Throttle and Debounce in your .NET projects. For see what is rate limiting you can run sample app or watch online sample.

This library is Extension on object type which can use for any type.

Read the article about rate-limiting in medium.

Nuget

This available on Nuget Packge Manager

PM> Install-Package RateLimiting

Debounce method

This method give last object when interval argument was fire time tick. For example: You have 20 item received less than 200 milisecond so debounceAction invoked after 20th item received and wait for another item for 200 milisecond.

private void OnPointerMoved(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
{
	pointerRoutedEventArgs.Pointer.Debounce(interval: 200, debounceAction: delegate(object o)
	{
		//Do any thing here you want in background

		//For use UI code use ---> await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { });
	});
}

Throttle method

This method give last object when interval argument was fire time tick. For example: You have 20 item received and 3 of them become after 200 milisecond, So throttleAction invoked when timer fired tick after 200 miliescond and get 3 item and invoked throttleAction callback.

private void OnPointerMoved(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
{
	pointerRoutedEventArgs.Pointer.Throttle(interval: 200, throttleAction: delegate(object o)
	{
	    //Do any thing here you want in background

	    //For use UI code use ---> await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { });
    	});
}

Example screenshot

Rate Limiting example screenshot