Throttle 0.1.0
dotnet add package Throttle --version 0.1.0
NuGet\Install-Package Throttle -Version 0.1.0
<PackageReference Include="Throttle" Version="0.1.0" />
<PackageVersion Include="Throttle" Version="0.1.0" />
<PackageReference Include="Throttle" />
paket add Throttle --version 0.1.0
#r "nuget: Throttle, 0.1.0"
#:package Throttle@0.1.0
#addin nuget:?package=Throttle&version=0.1.0
#tool nuget:?package=Throttle&version=0.1.0
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 | Versions 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. |
-
.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 |