Documentation ¶
Overview ¶
Package syncpool provides a non-leaky sync.Pool for github.com/klauspost/compress/zstd's Encoder and Decoder types, using wrappers (EncoderWrapper and DecoderWrapper).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDecoderPool ¶
NewDecoderPool returns a sync.Pool that provides DecoderWrapper objects, which embed *zstd.Decoders. You probably want to include zstd.WithDecoderConcurrency(1) in the list of options.
Types ¶
type DecoderWrapper ¶
type DecoderWrapper struct { // *zstd.Decoder is not safe for use in a sync.Pool directly, since it // leaks data and goroutines. Finalizers on the *zstd.Decoder don't help // because the aforementioned goroutines reference the *zstd.Decoder and // prevent it from being garbage collected (so the finalizers don't run). // // We can work around this by storing this wrapper with an embedded // *zstd.Decoder in the sync.Pool, and using a finalizer on the wrapper // to Close the *zstd.Decoder. *zstd.Decoder // contains filtered or unexported fields }
DecoderWrapper is a wrapper that embeds a *zstd.Decoder, and is safe for use in a sync.Pool.
func (*DecoderWrapper) Close ¶
func (w *DecoderWrapper) Close()
Close does not close the embedded *zstd.Decoder (once closed, they cannot be reused), but instead resets it and places this *DecoderWrapper back in the pool.
func (*DecoderWrapper) IOReadCloser ¶
func (w *DecoderWrapper) IOReadCloser() io.ReadCloser
IOReadCloser returns an io.ReadCloser that will return this *DecoderWrapper to the pool when it is closed.
type EncoderWrapper ¶
EncoderWrapper is a wrapper that embeds a *zstd.Encoder, and is safe for use in a sync.Pool.