You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this library helped you, consider buying me a coffee
12
-
13
-
<ahref="https://www.buymeacoffee.com/tomhurst"target="_blank"><imgsrc="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png"alt="Buy Me A Coffee"style="height: auto!important;width: auto!important;" ></a>
14
-
15
10
## Installation
16
-
.NET 6 Required
17
11
18
12
Install via Nuget
19
13
`Install-Package EnumerableAsyncProcessor`
20
14
21
15
## Why I built this
16
+
22
17
Because I've come across situations where you need to fine tune the rate at which you do things.
23
18
Maybe you want it fast.
24
19
Maybe you want it slow.
@@ -28,6 +23,7 @@ Maybe you just don't want to write all the boilerplate code that comes with mana
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set. As one finishes, another will start.
35
+
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set. As one finishes, another will start.
40
36
41
37
E.g. If you set a limit of 100, only 100 should ever run at any one time
42
38
43
39
This is a hybrid between Parallel Processor and Batch Processor (see below) - Trying to address the caveats of both. Increasing the speed of batching, but not overwhelming the system by using full parallelisation.
44
40
45
41
**Usage**
42
+
46
43
```csharp
47
44
varids=Enumerable.Range(0, 5000).ToList();
48
45
49
46
// SelectAsync for if you want to return something
50
-
varresults=awaitAsyncProcessorBuilder.WithItems(ids) // Or Extension Method: await ids.ToAsyncProcessorBuilder()
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set over the timespan that you set. As one finishes, another will start, unless you've hit the maximum allowed for the current timespan duration.
69
+
Processes your Asynchronous Tasks in Parallel, but honouring the limit that you set over the timespan that you set. As one finishes, another will start, unless you've hit the maximum allowed for the current timespan duration.
72
70
73
-
E.g. If you set a limit of 100, and a timespan of 1 second, only 100 operation should ever run at any one time over the course of a second. If the operation finishes sooner than a second (or your provided timespan), it'll wait and then start the next operation once that timespan has elapsed.
71
+
E.g. If you set a limit of 100, and a timespan of 1 second, only 100 operation should ever run at any one time over the course of a second. If the operation finishes sooner than a second (or your provided timespan), it'll wait and then start the next operation once that timespan has elapsed.
74
72
75
73
This is useful in scenarios where, for example, you have an API but it has a request per second limit
76
74
77
75
**Usage**
76
+
78
77
```csharp
79
78
varids=Enumerable.Range(0, 5000).ToList();
80
79
81
80
// SelectAsync for if you want to return something
82
-
varresults=awaitAsyncProcessorBuilder.WithItems(ids) // Or Extension Method: await ids.ToAsyncProcessorBuilder()
- If your operations take longer than your provided TimeSpan, you probably won't get your desired throughput. This processor ensures you don't go over your rate limit, but will not increase parallel execution if you're below it.
92
+
93
+
- If your operations take longer than your provided TimeSpan, you probably won't get your desired throughput. This processor ensures you don't go over your rate limit, but will not increase parallel execution if you're below it.
- Depending on how many operations you have, you could overwhelm your system. Memory and CPU and Network usage could spike, and cause bottlenecks / crashes / exceptions
195
+
196
+
- Depending on how many operations you have, you could overwhelm your system. Memory and CPU and Network usage could spike, and cause bottlenecks / crashes / exceptions
189
197
190
198
### Processor Methods
191
199
192
200
As above, you can see that you can just `await` on the processor to get the results.
193
201
Below shows examples of using the processor object and the various methods available.
194
202
195
203
This is for when you need to Enumerate through some objects and use them in your operations. E.g. Sending notifications to certain ids
204
+
196
205
```csharp
197
206
varhttpClient=newHttpClient();
198
207
@@ -229,6 +238,7 @@ This is for when you need to Enumerate through some objects and use them in your
229
238
```
230
239
231
240
This is for when you need to don't need any objects - But just want to do something a certain amount of times. E.g. Pinging a site to warm up multiple instances
0 commit comments