Soenneker.Utils.RateLimiting.Executor
3.0.78
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.RateLimiting.Executor --version 3.0.78
NuGet\Install-Package Soenneker.Utils.RateLimiting.Executor -Version 3.0.78
<PackageReference Include="Soenneker.Utils.RateLimiting.Executor" Version="3.0.78" />
paket add Soenneker.Utils.RateLimiting.Executor --version 3.0.78
#r "nuget: Soenneker.Utils.RateLimiting.Executor, 3.0.78"
// Install Soenneker.Utils.RateLimiting.Executor as a Cake Addin #addin nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=3.0.78 // Install Soenneker.Utils.RateLimiting.Executor as a Cake Tool #tool nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=3.0.78
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 | net9.0 is compatible. |
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Nito.AsyncEx (>= 5.1.2)
- Soenneker.Extensions.Task (>= 3.0.69)
- Soenneker.Extensions.ValueTask (>= 3.0.54)
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.114 | 31 | 12/17/2024 |
3.0.113 | 42 | 12/17/2024 |
3.0.112 | 18 | 12/17/2024 |
3.0.111 | 99 | 12/16/2024 |
3.0.110 | 212 | 12/10/2024 |
3.0.109 | 70 | 12/10/2024 |
3.0.108 | 150 | 12/10/2024 |
3.0.107 | 72 | 12/9/2024 |
3.0.106 | 154 | 12/9/2024 |
3.0.105 | 188 | 12/9/2024 |
3.0.104 | 69 | 12/9/2024 |
3.0.103 | 269 | 12/7/2024 |
3.0.102 | 92 | 12/6/2024 |
3.0.101 | 84 | 12/6/2024 |
3.0.100 | 86 | 12/6/2024 |
3.0.99 | 89 | 12/6/2024 |
3.0.97 | 116 | 12/6/2024 |
3.0.96 | 97 | 12/6/2024 |
3.0.95 | 72 | 12/6/2024 |
3.0.94 | 72 | 12/6/2024 |
3.0.93 | 75 | 12/6/2024 |
3.0.92 | 75 | 12/6/2024 |
3.0.91 | 110 | 12/6/2024 |
3.0.90 | 101 | 12/5/2024 |
3.0.89 | 99 | 12/5/2024 |
3.0.88 | 653 | 12/5/2024 |
3.0.87 | 110 | 12/5/2024 |
3.0.86 | 113 | 12/5/2024 |
3.0.85 | 163 | 12/5/2024 |
3.0.84 | 96 | 12/4/2024 |
3.0.83 | 120 | 12/4/2024 |
3.0.82 | 179 | 12/4/2024 |
3.0.81 | 158 | 12/4/2024 |
3.0.80 | 146 | 12/4/2024 |
3.0.79 | 75 | 12/3/2024 |
3.0.78 | 169 | 12/3/2024 |
3.0.77 | 170 | 12/3/2024 |
3.0.76 | 131 | 12/3/2024 |
3.0.75 | 63 | 12/3/2024 |
3.0.74 | 116 | 12/3/2024 |
3.0.73 | 62 | 12/3/2024 |
3.0.72 | 333 | 12/2/2024 |
3.0.71 | 124 | 12/2/2024 |
3.0.70 | 142 | 12/2/2024 |
3.0.69 | 69 | 12/2/2024 |
3.0.68 | 139 | 12/2/2024 |
3.0.67 | 190 | 12/1/2024 |
3.0.66 | 71 | 12/1/2024 |
3.0.65 | 229 | 12/1/2024 |
3.0.64 | 100 | 12/1/2024 |
3.0.63 | 185 | 11/29/2024 |
3.0.62 | 153 | 11/29/2024 |
3.0.61 | 240 | 11/21/2024 |
3.0.60 | 90 | 11/21/2024 |
3.0.59 | 240 | 11/20/2024 |
3.0.58 | 76 | 11/20/2024 |
3.0.57 | 104 | 11/20/2024 |
3.0.56 | 81 | 11/20/2024 |
3.0.55 | 81 | 11/20/2024 |
3.0.54 | 93 | 11/20/2024 |
3.0.53 | 88 | 11/19/2024 |
3.0.52 | 77 | 11/19/2024 |
3.0.51 | 75 | 11/19/2024 |
3.0.50 | 364 | 11/19/2024 |
3.0.49 | 70 | 11/19/2024 |
3.0.48 | 289 | 11/19/2024 |
3.0.47 | 77 | 11/19/2024 |
3.0.46 | 75 | 11/19/2024 |
3.0.45 | 276 | 11/15/2024 |
3.0.44 | 121 | 11/14/2024 |
3.0.43 | 73 | 11/14/2024 |
3.0.42 | 73 | 11/14/2024 |
3.0.41 | 121 | 11/14/2024 |
3.0.40 | 89 | 11/14/2024 |
3.0.39 | 199 | 11/14/2024 |
3.0.38 | 298 | 11/14/2024 |
3.0.37 | 141 | 11/14/2024 |
3.0.36 | 76 | 11/14/2024 |
3.0.35 | 78 | 11/14/2024 |
3.0.34 | 123 | 11/14/2024 |
3.0.33 | 79 | 11/14/2024 |
3.0.32 | 176 | 11/14/2024 |
2.1.31 | 278 | 11/13/2024 |
2.1.30 | 167 | 11/13/2024 |
2.1.29 | 237 | 11/13/2024 |
2.1.28 | 128 | 11/12/2024 |
2.1.27 | 73 | 11/12/2024 |
2.1.26 | 631 | 11/9/2024 |
2.1.25 | 163 | 11/9/2024 |
2.1.24 | 323 | 11/8/2024 |
2.1.23 | 81 | 11/8/2024 |
2.1.22 | 78 | 11/8/2024 |
2.1.21 | 272 | 11/8/2024 |
2.1.20 | 216 | 11/8/2024 |
2.1.19 | 237 | 11/6/2024 |
2.1.18 | 315 | 11/1/2024 |
2.1.17 | 75 | 11/1/2024 |
2.1.16 | 303 | 11/1/2024 |
2.1.14 | 90 | 10/29/2024 |
2.1.13 | 239 | 10/29/2024 |
2.1.12 | 127 | 10/29/2024 |
2.1.11 | 396 | 10/29/2024 |
2.1.10 | 240 | 10/28/2024 |
2.1.9 | 74 | 10/28/2024 |
2.1.8 | 104 | 10/28/2024 |
2.1.7 | 340 | 10/26/2024 |
2.1.6 | 102 | 10/26/2024 |
2.1.5 | 245 | 10/22/2024 |
2.1.4 | 103 | 10/22/2024 |
2.1.3 | 78 | 10/22/2024 |
2.1.2 | 87 | 10/22/2024 |
2.1.1 | 105 | 10/22/2024 |