https://github.com/jpmikkers/baksteen.async.concurrentprocessingqueue
Async queue that automatically processes items concurrently with a specified parallelism limit
https://github.com/jpmikkers/baksteen.async.concurrentprocessingqueue
csharp dispatcher dispatchqueue dotnet multiprocessing multithreading parallel parallel-computing queue
Last synced: 9 months ago
JSON representation
Async queue that automatically processes items concurrently with a specified parallelism limit
- Host: GitHub
- URL: https://github.com/jpmikkers/baksteen.async.concurrentprocessingqueue
- Owner: jpmikkers
- License: mit
- Created: 2023-11-23T15:31:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-01T12:59:15.000Z (about 2 years ago)
- Last Synced: 2025-02-06T01:44:41.509Z (11 months ago)
- Topics: csharp, dispatcher, dispatchqueue, dotnet, multiprocessing, multithreading, parallel, parallel-computing, queue
- Language: C#
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Baksteen.Async.ConcurrentProcessingQueue
Async queue that automatically processes items concurrently with a specified parallelism limit.
## Diagram

## Usage
```csharp
using System;
using System.Threading;
using System.Threading.Tasks;
using Baksteen.Async;
// create queue with a capacity of 5 items and a maximum of 8 concurrent process threads
// please note the 'await using' as this class is IAsyncDisposable
await using(var queue = new ConcurrentProcessingQueue(5, 8, processItem))
{
for(int t = 0; t < 100; t++)
{
Console.WriteLine($"enqueueing {t}");
await queue.Enqueue(t);
}
await queue.WaitForCompletion(); // this will wait until all items have been processed
}
static async ValueTask processItem(int x, CancellationToken ct)
{
Console.WriteLine($"processing item {x}");
// simulate some processing work:
await Task.Delay(Random.Shared.Next(500, 2000), ct);
}
```