Documentation
¶
Overview ¶
Package typedpipe implements a generic, in-memory, concurrency-safe pipe.
It provides a typed alternative to io.Pipe: values of type T can be passed between goroutines with backpressure and coordinated shutdown semantics.
The pipe guarantees:
- Safe concurrent use.
- Blocking reads and writes.
- Idempotent close.
- Propagation of the first close error to all subsequent operations.
- Full drain of buffered values before returning a close error to readers.
Shutdown semantics:
Either side (Reader or Writer) may call Close/CloseWithError. When closed:
- All in-progress and future Write calls return the close error immediately.
- Read calls drain any buffered values, then return the close error.
Note: Because both sides share a Closer, a reader may close the writer's side and vice versa. This matches io.Pipe semantics and is intentional.
Index ¶
Constants ¶
const ( // DefaultBufferSize is the default channel capacity. DefaultBufferSize = 64 // MaxBufferSize is the maximum allowed buffer capacity. // New returns an error if the requested size exceeds this value. MaxBufferSize = 2048 )
Variables ¶
var ErrPipeClosed = errors.New("pipe is closed")
ErrPipeClosed is returned by operations on a closed pipe when no custom error was provided to CloseWithError.
Functions ¶
Types ¶
type Closer ¶
type Closer interface {
Close()
CloseWithError(err error)
}
Closer is the shared shutdown interface. The first non-nil error passed to CloseWithError is retained; subsequent calls are no-ops.
type Option ¶
type Option func(*options)
Option configures a pipe at construction time.
func WithBufferSize ¶
WithBufferSize sets the pipe's internal channel capacity. A value <= 0 produces an unbuffered (synchronous) pipe. Values > MaxBufferSize cause New() to return an error.