Soenneker.Utils.RateLimiting.Executor 3.0.66

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Utils.RateLimiting.Executor --version 3.0.66                
NuGet\Install-Package Soenneker.Utils.RateLimiting.Executor -Version 3.0.66                
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="Soenneker.Utils.RateLimiting.Executor" Version="3.0.66" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.Utils.RateLimiting.Executor --version 3.0.66                
#r "nuget: Soenneker.Utils.RateLimiting.Executor, 3.0.66"                
#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.
// Install Soenneker.Utils.RateLimiting.Executor as a Cake Addin
#addin nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=3.0.66

// Install Soenneker.Utils.RateLimiting.Executor as a Cake Tool
#tool nuget:?package=Soenneker.Utils.RateLimiting.Executor&version=3.0.66                

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.110 64 12/10/2024
3.0.109 34 12/10/2024
3.0.108 74 12/10/2024
3.0.107 35 12/9/2024
3.0.106 74 12/9/2024
3.0.105 107 12/9/2024
3.0.104 36 12/9/2024
3.0.103 144 12/7/2024
3.0.102 48 12/6/2024
3.0.101 44 12/6/2024
3.0.100 47 12/6/2024
3.0.99 50 12/6/2024
3.0.97 68 12/6/2024
3.0.96 54 12/6/2024
3.0.95 39 12/6/2024
3.0.94 40 12/6/2024
3.0.93 41 12/6/2024
3.0.92 40 12/6/2024
3.0.91 68 12/6/2024
3.0.90 53 12/5/2024
3.0.89 56 12/5/2024
3.0.88 369 12/5/2024
3.0.87 61 12/5/2024
3.0.86 65 12/5/2024
3.0.85 84 12/5/2024
3.0.84 75 12/4/2024
3.0.83 95 12/4/2024
3.0.82 108 12/4/2024
3.0.81 121 12/4/2024
3.0.80 118 12/4/2024
3.0.79 68 12/3/2024
3.0.78 124 12/3/2024
3.0.77 156 12/3/2024
3.0.76 126 12/3/2024
3.0.75 58 12/3/2024
3.0.74 111 12/3/2024
3.0.73 57 12/3/2024
3.0.72 307 12/2/2024
3.0.71 118 12/2/2024
3.0.70 135 12/2/2024
3.0.69 62 12/2/2024
3.0.68 132 12/2/2024
3.0.67 181 12/1/2024
3.0.66 64 12/1/2024
3.0.65 222 12/1/2024
3.0.64 93 12/1/2024
3.0.63 180 11/29/2024
3.0.62 150 11/29/2024
3.0.61 238 11/21/2024
3.0.60 88 11/21/2024
3.0.59 238 11/20/2024
3.0.58 74 11/20/2024
3.0.57 102 11/20/2024
3.0.56 79 11/20/2024
3.0.55 79 11/20/2024
3.0.54 91 11/20/2024
3.0.53 86 11/19/2024
3.0.52 75 11/19/2024
3.0.51 71 11/19/2024
3.0.50 362 11/19/2024
3.0.49 68 11/19/2024
3.0.48 287 11/19/2024
3.0.47 75 11/19/2024
3.0.46 73 11/19/2024
3.0.45 274 11/15/2024
3.0.44 119 11/14/2024
3.0.43 71 11/14/2024
3.0.42 71 11/14/2024
3.0.41 119 11/14/2024
3.0.40 87 11/14/2024
3.0.39 197 11/14/2024
3.0.38 292 11/14/2024
3.0.37 139 11/14/2024
3.0.36 74 11/14/2024
3.0.35 76 11/14/2024
3.0.34 121 11/14/2024
3.0.33 77 11/14/2024
3.0.32 174 11/14/2024
2.1.31 276 11/13/2024
2.1.30 163 11/13/2024
2.1.29 235 11/13/2024
2.1.28 126 11/12/2024
2.1.27 69 11/12/2024
2.1.26 627 11/9/2024
2.1.25 161 11/9/2024
2.1.24 321 11/8/2024
2.1.23 79 11/8/2024
2.1.22 76 11/8/2024
2.1.21 270 11/8/2024
2.1.20 214 11/8/2024
2.1.19 235 11/6/2024
2.1.18 313 11/1/2024
2.1.17 73 11/1/2024
2.1.16 301 11/1/2024
2.1.14 87 10/29/2024
2.1.13 236 10/29/2024
2.1.12 124 10/29/2024
2.1.11 393 10/29/2024
2.1.10 235 10/28/2024
2.1.9 71 10/28/2024
2.1.8 99 10/28/2024
2.1.7 334 10/26/2024
2.1.6 95 10/26/2024
2.1.5 241 10/22/2024
2.1.4 99 10/22/2024
2.1.3 74 10/22/2024
2.1.2 84 10/22/2024
2.1.1 102 10/22/2024