Throttle 0.1.0

dotnet add package Throttle --version 0.1.0
                    
NuGet\Install-Package Throttle -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Throttle" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Throttle" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Throttle" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Throttle --version 0.1.0
                    
#r "nuget: Throttle, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Throttle@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Throttle&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Throttle&version=0.1.0
                    
Install as a Cake Tool

Throttle

Throttle multiple asynchronous functions

Repository

The source code is available on GitHub.

Usage

First you need to add the Throttle namespace to your project.

using Throttle;

Then you will have access to the Throttler class, which have two overloaded static methods: Task Throttler.Throttle(IEnumerable<Func<Task>> callbacks, int ticks) and Task<IEnumerable<T>> Throttler.Throttle<T>(IEnumerable<Func<Task<T>>> callbacks, int ticks).

Task Throttler.Throttle(IEnumerable<Func<Task>> callbacks, int ticks)

This method is used to throttle asynchronous functions that does not return any value.

Example:

var callbacks = new List<Func<Task>>
{
    async () => { await Task.Delay(1000); Console.WriteLine("Callback 1"); },
    async () => { await Task.Delay(1000); Console.WriteLine("Callback 2"); },
    async () => { await Task.Delay(2000); Console.WriteLine("Callback 3"); },
    async () => { await Task.Delay(2000); Console.WriteLine("Callback 4"); },
    async () => { await Task.Delay(3000); Console.WriteLine("Callback 5"); },
    async () => { await Task.Delay(3000); Console.WriteLine("Callback 6"); },
    async () => { await Task.Delay(10000); Console.WriteLine("Callback 7"); }
};

await Throttler.Throttle(callbacks, 2);

Will result in something like:

$ dotnet run
# After ~1 second
Callback 2
Callback 1
# After ~2 seconds
Callback 4
Callback 3
# After ~3 seconds
Callback 6
Callback 5
# After ~10 seconds
Callback 7
Task<IEnumerable<T>> Throttler.Throttle<T>(IEnumerable<Func<Task<T>>> callbacks, int ticks)

This method is used to throttle asynchronous functions that does return a value, specified in the method generic.

Example:

var callbacks = new List<Func<Task<int>>>
{
    async () => { await Task.Delay(1000); Console.WriteLine("Callback 1"); return 1; },
    async () => { await Task.Delay(1000); Console.WriteLine("Callback 2"); return 2; },
    async () => { await Task.Delay(2000); Console.WriteLine("Callback 3"); return 3; },
    async () => { await Task.Delay(2000); Console.WriteLine("Callback 4"); return 4; },
    async () => { await Task.Delay(3000); Console.WriteLine("Callback 5"); return 5; },
    async () => { await Task.Delay(3000); Console.WriteLine("Callback 6"); return 6; },
    async () => { await Task.Delay(10000); Console.WriteLine("Callback 7"); return 7; }
};

System.Console.WriteLine(string.Join(", ", await Throttler.Throttle(callbacks, 2)));

Will result in something like:

$ dotnet run
# After ~1 second
Callback 2
Callback 1
# After ~2 seconds
Callback 4
Callback 3
# After ~3 seconds
Callback 6
Callback 5
# After ~10 seconds
Callback 7
# After finished
1, 2, 3, 4, 5, 6, 7
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Throttle:

Package Downloads
GraphInterface

Simple Microsoft Graph API client

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 1,048 12/26/2021