Soenneker.Utils.RateLimiting.Executor
2.1.23
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.RateLimiting.Executor --version 2.1.23
NuGet\Install-Package Soenneker.Utils.RateLimiting.Executor -Version 2.1.23
<PackageReference Include="Soenneker.Utils.RateLimiting.Executor" Version="2.1.23" />
paket add Soenneker.Utils.RateLimiting.Executor --version 2.1.23
#r "nuget: Soenneker.Utils.RateLimiting.Executor, 2.1.23"
// Install Soenneker.Utils.RateLimiting.Executor as a Cake Addin #addin nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=2.1.23 // Install Soenneker.Utils.RateLimiting.Executor as a Cake Tool #tool nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=2.1.23
Soenneker.Utils.RateLimiting.Executor
A thread-safe utility designed to manage the rate at which tasks are executed, ensuring they are not run more frequently than a specified interval.
RateLimitingExecutor
is ideal for interacting with rate-limited APIs or throttling the execution of resource-intensive tasks.
Sequential Execution
Tasks
, ValueTasks
, and Actions
are executed one at a time. If the defined interval between executions has passed, the task runs immediately; otherwise, it waits until the interval elapses before proceeding.
⚠️ Important Notes:
This is not a background queue processor. Each method awaits the result of the asynchronous operation before continuing.
Asynchronous methods will not block the calling thread, but synchronous methods will block execution until it completes.
Want to use this with dependency injection?
Check out the singleton factory implementation: Soenneker.Utils.RateLimiting.Factory
Installation
dotnet add package Soenneker.Utils.RateLimiting.Executor
Example: Executing a Loop of Tasks with Rate Limiting
Below is an example demonstrating how to use the RateLimitingExecutor to execute a series of tasks while maintaining a rate limit.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Soenneker.Utils.RateLimiting.Executor;
public class Program
{
public static async Task Main(string[] args)
{
var rateLimitingExecutor = new RateLimitingExecutor(TimeSpan.FromSeconds(2));
for (int i = 0; i < 5; i++)
{
await rateLimitingExecutor.Execute(async ct =>
{
Console.WriteLine($"Executing Task {i + 1} at {DateTime.Now:HH:mm:ss}");
await Task.Delay(100); // Simulate some work
});
}
}
}
Console Output
Executing Task 1 at 14:00:00
Executing Task 2 at 14:00:02
Executing Task 3 at 14:00:04
Executing Task 4 at 14:00:06
Executing Task 5 at 14:00:08
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Nito.AsyncEx (>= 5.1.2)
- Soenneker.Extensions.Task (>= 2.1.66)
- Soenneker.Extensions.ValueTask (>= 2.1.51)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Utils.RateLimiting.Executor:
Package | Downloads |
---|---|
Soenneker.Utils.RateLimiting.Factory
An async thread-safe singleton dictionary for Soenneker.Utils.RateLimiting.Executors, designed to manage the rate at which tasks are executed. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.63 | 39 | 11/29/2024 |
3.0.62 | 64 | 11/29/2024 |
3.0.61 | 167 | 11/21/2024 |
3.0.60 | 84 | 11/21/2024 |
3.0.59 | 235 | 11/20/2024 |
3.0.58 | 70 | 11/20/2024 |
3.0.57 | 96 | 11/20/2024 |
3.0.56 | 73 | 11/20/2024 |
3.0.55 | 75 | 11/20/2024 |
3.0.54 | 88 | 11/20/2024 |
3.0.53 | 82 | 11/19/2024 |
3.0.52 | 69 | 11/19/2024 |
3.0.51 | 68 | 11/19/2024 |
3.0.50 | 358 | 11/19/2024 |
3.0.49 | 64 | 11/19/2024 |
3.0.48 | 280 | 11/19/2024 |
3.0.47 | 68 | 11/19/2024 |
3.0.46 | 68 | 11/19/2024 |
3.0.45 | 267 | 11/15/2024 |
3.0.44 | 114 | 11/14/2024 |
3.0.43 | 65 | 11/14/2024 |
3.0.42 | 64 | 11/14/2024 |
3.0.41 | 115 | 11/14/2024 |
3.0.40 | 81 | 11/14/2024 |
3.0.39 | 192 | 11/14/2024 |
3.0.38 | 288 | 11/14/2024 |
3.0.37 | 130 | 11/14/2024 |
3.0.36 | 65 | 11/14/2024 |
3.0.35 | 67 | 11/14/2024 |
3.0.34 | 112 | 11/14/2024 |
3.0.33 | 68 | 11/14/2024 |
3.0.32 | 166 | 11/14/2024 |
2.1.31 | 269 | 11/13/2024 |
2.1.30 | 153 | 11/13/2024 |
2.1.29 | 230 | 11/13/2024 |
2.1.28 | 121 | 11/12/2024 |
2.1.27 | 64 | 11/12/2024 |
2.1.26 | 533 | 11/9/2024 |
2.1.25 | 154 | 11/9/2024 |
2.1.24 | 316 | 11/8/2024 |
2.1.23 | 75 | 11/8/2024 |
2.1.22 | 72 | 11/8/2024 |
2.1.21 | 265 | 11/8/2024 |
2.1.20 | 209 | 11/8/2024 |
2.1.19 | 230 | 11/6/2024 |
2.1.18 | 308 | 11/1/2024 |
2.1.17 | 69 | 11/1/2024 |
2.1.16 | 298 | 11/1/2024 |
2.1.14 | 83 | 10/29/2024 |
2.1.13 | 234 | 10/29/2024 |
2.1.12 | 122 | 10/29/2024 |
2.1.11 | 391 | 10/29/2024 |
2.1.10 | 232 | 10/28/2024 |
2.1.9 | 68 | 10/28/2024 |
2.1.8 | 97 | 10/28/2024 |
2.1.7 | 333 | 10/26/2024 |
2.1.6 | 92 | 10/26/2024 |
2.1.5 | 240 | 10/22/2024 |
2.1.4 | 96 | 10/22/2024 |
2.1.3 | 72 | 10/22/2024 |
2.1.2 | 82 | 10/22/2024 |
2.1.1 | 99 | 10/22/2024 |