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/bounded-capacity-and-backpressure.md
View on GitHub# Bounded Capacity And Backpressure
## Choose Capacity Deliberately
Prefer a bounded channel unless the backlog is provably finite and controlled. Capacity limits queued item count, not bytes; use realistic payload size and memory budgets when sizing it.
| Full Mode | Behavior | Appropriate For |
| --- | --- | --- |
| `Wait` | `WriteAsync` waits; `TryWrite` returns `false` | Lossless work and backpressure to the producer |
| `DropWrite` | Rejects the incoming item | Best-effort telemetry where new data may be discarded |
| `DropNewest` | Removes the newest queued item for the incoming item | Rare policies where older work is more valuable |
| `DropOldest` | Removes the oldest queued item for the incoming item | Latest-state/sampling updates where stale work is useless |
Treat every drop policy as a product decision. The producer must tolerate loss, and operations must observe it through the `itemDropped` callback, metrics, or both.
## Overload Behavior
- `Wait` applies backpressure. Propagate the `WriteAsync` task to the caller when admission must slow down or fail with the request.
- Do not turn `WriteAsync` into unbounded background tasks to avoid waiting; that moves the unbounded queue into the task scheduler.
- Reject, shed, coalesce, or persist work explicitly when waiting cannot be allowed on a request path.
- Measure producer wait time, queue depth if instrumented by the owner, item age, dropped count, consumer duration, failures, and shutdown drain time.
- Use unbounded channels only when input rate is controlled, all producers are trusted, and memory growth is demonstrably bounded by another mechanism.
## Options
```csharp
var channel = Channel.CreateBounded<WorkItem>(
new BoundedChannelOptions(capacity: 256)
{
FullMode = BoundedChannelFullMode.Wait,
SingleWriter = false,
SingleReader = true,
AllowSynchronousContinuations = false,
});
```
- Set `SingleWriter`/`SingleReader` to `true` only for actual single-owner paths; incorrect promises are concurrency bugs.
- Leave `AllowSynchronousContinuations` at its conservative default unless inline continuation execution is accepted and profiled. It can reduce scheduling overhead but introduce reentrancy and producer latency.
## Sources
- [Channels: bounding strategies](https://learn.microsoft.com/dotnet/core/extensions/channels#bounding-strategies)
- [BoundedChannelFullMode](https://learn.microsoft.com/dotnet/api/system.threading.channels.boundedchannelfullmode)
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 |