NetFabric/intelligentium / plugins/dotnet/.apm/skills/dotnet-channels
dotnet-channels
VerifiedDesign, implement, debug, test, and review in-process producer-consumer pipelines with System.Threading.Channels. USE FOR: Channel<T>, ChannelReader<T>, ChannelWriter<T>, bounded/unbounded queues, BoundedChannelFullMode, backpressure, TryWrite, WriteAsync, ReadAsync, ReadAllAsync, completion, cancellation, concurrent producers/consumers, BackgroundService workers, in-memory event queues, overload protection, and channel performance. DO NOT USE FOR: durable or cross-process messaging, distributed pub/sub, broker delivery guarantees, Rx.NET stream composition, task-parallel dataflow blocks, or simple thread-safe collections with no asynchronous producer-consumer requirement.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.3 KB |
| references/bounded-capacity-and-backpressure.md | markdown | 2.5 KB |
| references/concurrency-and-consumption.md | markdown | 2.4 KB |
| references/contracts-and-api.md | markdown | 3.0 KB |
| references/hosted-services-and-di.md | markdown | 2.1 KB |
| references/in-memory-messaging-boundaries.md | markdown | 1.8 KB |
| references/sources.md | markdown | 1.6 KB |
| references/testing-and-review.md | markdown | 2.2 KB |
references/concurrency-and-consumption.md
View on GitHub# Concurrency And Consumption
## Producer And Consumer Topology
| Topology | Configure | Consequence |
| --- | --- | --- |
| One producer, one consumer | `SingleWriter = true`, `SingleReader = true` | FIFO processing with simplest ownership |
| Many producers, one consumer | `SingleWriter = false`, `SingleReader = true` | One serialized processing stream |
| One producer, many consumers | `SingleWriter = true`, `SingleReader = false` | Items are distributed, not broadcast |
| Many producers, many consumers | Both `false` | Throughput increases; completion and ordering require coordination |
A channel is a work queue, not a pub/sub topic. Multiple consumers compete for items; each item is delivered to one consumer only. Give every subscriber a separate channel or use a broker/observable design when fan-out is required.
## Completion Ownership
- Assign one component as the completion owner. With multiple producers, await all producer tasks before it calls `TryComplete`.
- Do not let an individual producer complete a shared writer unless it owns the entire producer set.
- If producer failure should stop the pipeline, coordinate `TryComplete(exception)` once and observe the reader completion fault.
## Process Sequentially Or In Parallel
- A single consumer preserves channel dequeue order and is easiest to reason about.
- Multiple consumers improve throughput but completion order is nondeterministic. Do not use them when effects must be globally ordered.
- For bounded parallelism while retaining one dequeue owner, read sequentially and limit processing with a semaphore or a bounded worker pool. Define per-key ordering if required.
- Use `ReadAllAsync` for straightforward processing. Use `WaitToReadAsync` plus `TryRead` for explicit batch draining and to reduce await overhead under load.
## Safe Batch Drain
```csharp
while (await reader.WaitToReadAsync(cancellationToken))
{
while (reader.TryRead(out WorkItem item))
{
await ProcessAsync(item, cancellationToken);
}
}
```
Do not hold a read item indefinitely while waiting for unrelated external work. Bound concurrent processing and ensure every failure path either retries intentionally, records the failure, or stops the service.
## Sources
- [Channels: multiple producers and consumers](https://learn.microsoft.com/dotnet/core/extensions/channels#multiple-producers-and-consumers)
- [Channels: consumer patterns](https://learn.microsoft.com/dotnet/core/extensions/channels#consumer-patterns)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |