Soenneker.Utils.RateLimiting.Executor 3.0.172

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.172                
NuGet\Install-Package Soenneker.Utils.RateLimiting.Executor -Version 3.0.172                
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.172" />                
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.172                
#r "nuget: Soenneker.Utils.RateLimiting.Executor, 3.0.172"                
#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.172

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

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.173 32 12/28/2024
3.0.172 37 12/28/2024
3.0.171 54 12/27/2024
3.0.170 37 12/27/2024
3.0.169 231 12/24/2024
3.0.168 145 12/24/2024
3.0.167 94 12/24/2024
3.0.166 77 12/24/2024
3.0.165 156 12/24/2024
3.0.164 67 12/24/2024
3.0.163 159 12/24/2024
3.0.162 61 12/24/2024
3.0.161 104 12/24/2024
3.0.160 79 12/23/2024
3.0.159 136 12/23/2024
3.0.158 150 12/23/2024
3.0.157 75 12/23/2024
3.0.156 244 12/23/2024
3.0.155 90 12/23/2024
3.0.154 233 12/22/2024
3.0.153 74 12/22/2024
3.0.152 71 12/22/2024
3.0.151 184 12/22/2024
3.0.150 78 12/22/2024
3.0.149 73 12/22/2024
3.0.148 68 12/22/2024
3.0.147 252 12/22/2024
3.0.146 75 12/22/2024
3.0.145 81 12/22/2024
3.0.144 72 12/22/2024
3.0.143 238 12/21/2024
3.0.142 73 12/21/2024
3.0.141 84 12/21/2024
3.0.140 69 12/21/2024
3.0.139 74 12/21/2024
3.0.138 67 12/21/2024
3.0.137 70 12/21/2024
3.0.136 75 12/21/2024
3.0.135 260 12/21/2024
3.0.134 156 12/21/2024
3.0.133 70 12/21/2024
3.0.132 73 12/21/2024
3.0.131 63 12/21/2024
3.0.130 217 12/21/2024
3.0.129 71 12/21/2024
3.0.128 121 12/20/2024
3.0.127 65 12/20/2024
3.0.126 147 12/20/2024
3.0.125 70 12/20/2024
3.0.124 171 12/20/2024
3.0.123 146 12/20/2024
3.0.122 74 12/20/2024
3.0.121 148 12/20/2024
3.0.120 172 12/19/2024
3.0.119 146 12/19/2024
3.0.118 80 12/19/2024
3.0.117 126 12/19/2024
3.0.116 73 12/18/2024
3.0.115 121 12/18/2024
3.0.114 178 12/17/2024
3.0.113 91 12/17/2024
3.0.112 53 12/17/2024
3.0.111 189 12/16/2024
3.0.110 273 12/10/2024
3.0.109 74 12/10/2024
3.0.108 154 12/10/2024
3.0.107 76 12/9/2024
3.0.106 159 12/9/2024
3.0.105 191 12/9/2024
3.0.104 72 12/9/2024
3.0.103 274 12/7/2024
3.0.102 97 12/6/2024
3.0.101 89 12/6/2024
3.0.100 91 12/6/2024
3.0.99 94 12/6/2024
3.0.97 121 12/6/2024
3.0.96 102 12/6/2024
3.0.95 77 12/6/2024
3.0.94 79 12/6/2024
3.0.93 80 12/6/2024
3.0.92 80 12/6/2024
3.0.91 115 12/6/2024
3.0.90 108 12/5/2024
3.0.89 104 12/5/2024
3.0.88 658 12/5/2024
3.0.87 116 12/5/2024
3.0.86 118 12/5/2024
3.0.85 168 12/5/2024
3.0.84 102 12/4/2024
3.0.83 127 12/4/2024
3.0.82 183 12/4/2024
3.0.81 171 12/4/2024
3.0.80 153 12/4/2024
3.0.79 80 12/3/2024
3.0.78 176 12/3/2024
3.0.77 175 12/3/2024
3.0.76 136 12/3/2024
3.0.75 70 12/3/2024
3.0.74 121 12/3/2024
3.0.73 67 12/3/2024
3.0.72 339 12/2/2024
3.0.71 129 12/2/2024
3.0.70 149 12/2/2024
3.0.69 74 12/2/2024
3.0.68 146 12/2/2024
3.0.67 196 12/1/2024
3.0.66 76 12/1/2024
3.0.65 234 12/1/2024
3.0.64 108 12/1/2024
3.0.63 188 11/29/2024
3.0.62 156 11/29/2024
3.0.61 243 11/21/2024
3.0.60 93 11/21/2024
3.0.59 245 11/20/2024
3.0.58 79 11/20/2024
3.0.57 109 11/20/2024
3.0.56 84 11/20/2024
3.0.55 84 11/20/2024
3.0.54 96 11/20/2024
3.0.53 91 11/19/2024
3.0.52 82 11/19/2024
3.0.51 78 11/19/2024
3.0.50 367 11/19/2024
3.0.49 75 11/19/2024
3.0.48 294 11/19/2024
3.0.47 80 11/19/2024
3.0.46 78 11/19/2024
3.0.45 279 11/15/2024
3.0.44 124 11/14/2024
3.0.43 76 11/14/2024
3.0.42 76 11/14/2024
3.0.41 124 11/14/2024
3.0.40 92 11/14/2024
3.0.39 204 11/14/2024
3.0.38 301 11/14/2024
3.0.37 144 11/14/2024
3.0.36 79 11/14/2024
3.0.35 81 11/14/2024
3.0.34 126 11/14/2024
3.0.33 82 11/14/2024
3.0.32 181 11/14/2024
2.1.31 281 11/13/2024
2.1.30 170 11/13/2024
2.1.29 240 11/13/2024
2.1.28 131 11/12/2024
2.1.27 76 11/12/2024
2.1.26 634 11/9/2024
2.1.25 166 11/9/2024
2.1.24 327 11/8/2024
2.1.23 85 11/8/2024
2.1.22 82 11/8/2024
2.1.21 276 11/8/2024
2.1.20 220 11/8/2024
2.1.19 241 11/6/2024
2.1.18 319 11/1/2024
2.1.17 79 11/1/2024
2.1.16 307 11/1/2024
2.1.14 93 10/29/2024
2.1.13 242 10/29/2024
2.1.12 130 10/29/2024
2.1.11 399 10/29/2024
2.1.10 243 10/28/2024
2.1.9 77 10/28/2024
2.1.8 107 10/28/2024
2.1.7 343 10/26/2024
2.1.6 105 10/26/2024
2.1.5 251 10/22/2024
2.1.4 107 10/22/2024
2.1.3 84 10/22/2024
2.1.2 91 10/22/2024
2.1.1 111 10/22/2024