aalmada/Stationary / .agents/skills/dotnet-pipelines
dotnet-pipelines
VerifiedDesign, implement, debug, test, and review high-throughput byte-stream processing with System.IO.Pipelines. USE FOR: Pipe, PipeReader, PipeWriter, ReadResult, FlushResult, ReadOnlySequence, SequenceReader, buffer lifecycle, AdvanceTo, GetMemory, Advance, FlushAsync, stream and socket adapters, framing protocols, incremental parsing, backpressure, cancellation, and Pipes-to-Channels handoff. DO NOT USE FOR: item-level producer-consumer queues, durable/distributed messaging, ordinary small file I/O with no measured bottleneck, generic Stream APIs with no buffer-management concern, or ASP.NET middleware pipelines unrelated to System.IO.Pipelines.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.6 KB |
| references/pipes-and-channels-boundary.md | markdown | 1.9 KB |
| references/reader-parsing-and-lifetime.md | markdown | 2.7 KB |
| references/sources.md | markdown | 1.5 KB |
| references/streams-sockets-and-ownership.md | markdown | 2.0 KB |
| references/testing-performance-and-review.md | markdown | 2.4 KB |
| references/writer-flow-control-and-completion.md | markdown | 2.3 KB |
references/writer-flow-control-and-completion.md
View on GitHub# Writer Flow Control And Completion
## Writer Loop
Reserve memory, write bytes, commit the written count, then flush. `FlushAsync` publishes bytes and applies the pipe's pause/resume thresholds.
```csharp
try
{
while (true)
{
Memory<byte> destination = writer.GetMemory(minimumBufferSize);
int bytesRead = await source.ReadAsync(destination, cancellationToken);
if (bytesRead == 0)
{
break;
}
writer.Advance(bytesRead);
FlushResult flush = await writer.FlushAsync(cancellationToken);
if (flush.IsCompleted || flush.IsCanceled)
{
break;
}
}
}
finally
{
await writer.CompleteAsync();
}
```
Do not call `Advance` with bytes not initialized by the producer. Do not retain writer-provided memory after a flush or completion.
## Flow Control
| Setting | Effect |
| --- | --- |
| `PauseWriterThreshold` | Buffered-byte level where `FlushAsync` starts waiting |
| `ResumeWriterThreshold` | Buffered-byte level where a blocked flush may continue |
| `MinimumSegmentSize` | Minimum rented buffer size for writer requests |
| `UseSynchronizationContext` | Whether continuations capture the current synchronization context |
- Tune thresholds only after measurement. They constrain buffered bytes but do not replace protocol message limits.
- Await every `FlushAsync`; ignoring its pending result defeats flow control and hides completion/cancellation.
- Keep pause thresholds comfortably above typical frames but bounded by a real memory budget.
## Completion And Cancellation
- The component owning the full write loop calls `CompleteAsync`, including an exception when it owns a terminal fault.
- Completing the writer tells the reader no more bytes will arrive; readers must still drain the existing buffer.
- `ReadAsync`/`FlushAsync` accept cancellation tokens. `CancelPendingRead` and `CancelPendingFlush` produce a result with `IsCanceled` instead of throwing and are useful for a controlled loop exit.
- Stop writing when `FlushResult.IsCompleted` is true: the reader no longer accepts data.
## Sources
- [System.IO.Pipelines: Pipe](https://learn.microsoft.com/dotnet/standard/io/pipelines#pipe)
- [PipeOptions](https://learn.microsoft.com/dotnet/api/system.io.pipelines.pipeoptions)
- [PipeWriter](https://learn.microsoft.com/dotnet/api/system.io.pipelines.pipewriter)
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 |