bp

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 3

README

bp

Apache License GoDoc Go Report Card Releases

bp implements buffer pool of various objects such as byte array ([]byte) or *bytes.Buffer / *image.RGBA and *bufio.Reader.
It is inspired by bpool and its many features are similar.

bp provides the following pool types

  • bp.BufferPool which provides fixed-size pool of *bytes.Buffers
  • bp.BytePool which provides fixed-size pool of []byte slice
  • bp.MmapBytePool Same as BytePool, but uses mmap to allocate the slices
  • bp.BufioReaderPool which provides fixed-size pool of *bufio.Reader
  • bp.BufioWriterPool which provides fixed-size pool of *bufio.Writer
  • bp.ImageRGBAPool which provides fixed-size pool of *image.RGBA
  • bp.ImageYCbCrPool which provides fixed-size pool of *image.YCbCr
  • bp.CopyIOPool which provides fixed-size pool of io.CopyBuffer and io.ReadAll
  • bp.TickerPool which provides fixed-size pool of *time.Ticker
  • bp.TimerPool which provides fixed-size pool of *time.Timer

It also provides a MultiPool to bundle multiple pools:

  • MultiBytePool
  • MultiMmapBytePool
  • MultiBufferPool
  • MultiImageRGBAPool
  • MultiImageYCbCrPool

In addition, bp provides an easy to manipulate object interface to prevent forgetting to put it back into the pool

  • bp.ByteRef
  • bp.BufferRef
  • bp.BufioReaderRef
  • bp.BufioWriterRef
  • bp.ImageRGBARef
  • bp.ImageYCbCrRef

Installation

go get github.com/octu0/bp

Example

Here's a quick example for using bp.BufferPool. We create a pool of the desired size, call the Get() method to obtain a buffer for use, and call Put(buf) to return the buffer to the pool.

var (
  bufpool := bp.NewBufferPool(1000, 128) // capacity 1000 items, each buffer initial 128 Byte pre-sized
)

func main() {
  // get buffer from pool
  buf := bufpool.Get()
  ...
  ...
  // return buffer to pool
  bufpool.Put(buf)
}

Benchmark

bytes.Buffer: sync.Pool vs BufferPool

$ go test -bench=BenchmarkBufferPool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkBufferPool/default/8-8         	 1608904	       768.9 ns/op	      32 B/op	       1 allocs/op
BenchmarkBufferPool/default/4096-8      	 1421576	       791.1 ns/op	      32 B/op	       1 allocs/op
BenchmarkBufferPool/syncpool/8-8        	 1584180	       743.3 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferPool/syncpool/4096-8     	 1505594	       798.4 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferPool/bufferpool/8-8      	 1439310	       917.2 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferPool/bufferpool/4096-8   	 1225413	       967.4 ns/op	      48 B/op	       1 allocs/op
PASS
ok  	github.com/octu0/bp	12.309s

[]byte: sync.Pool vs BytePool

$ go test -bench=BenchmarkBytePool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkBytePool/default/8-8         	 1827867	       653.8 ns/op	      16 B/op	       1 allocs/op
BenchmarkBytePool/default/4096-8      	 1562638	       788.3 ns/op	      16 B/op	       1 allocs/op
BenchmarkBytePool/syncpool/8-8        	 1643428	       763.2 ns/op	      48 B/op	       2 allocs/op
BenchmarkBytePool/syncpool/4096-8     	 1586283	       803.8 ns/op	      48 B/op	       2 allocs/op
BenchmarkBytePool/bytepool/8-8        	 1357020	       904.1 ns/op	      24 B/op	       1 allocs/op
BenchmarkBytePool/bytepool/4096-8     	 1359921	       846.6 ns/op	      24 B/op	       1 allocs/op
PASS
ok  	github.com/octu0/bp	12.105s

bufio.Reader: sync.Pool vs BufioReaderPool

$ go test -bench=BenchmarkBufioReaderPool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkBufioReaderPool/default/8-8         	 1000000	      1120 ns/op	    1056 B/op	       3 allocs/op
BenchmarkBufioReaderPool/default/4096-8      	  803418	      1542 ns/op	    5136 B/op	       3 allocs/op
BenchmarkBufioReaderPool/syncpool/8-8        	 1000000	      1102 ns/op	    1048 B/op	       2 allocs/op
BenchmarkBufioReaderPool/syncpool/4096-8     	 1000000	      1110 ns/op	    1051 B/op	       2 allocs/op
BenchmarkBufioReaderPool/bufiopool/8-8       	 1000000	      1290 ns/op	    1160 B/op	       4 allocs/op
BenchmarkBufioReaderPool/bufiopool/4096-8    	  918162	      1279 ns/op	    1048 B/op	       2 allocs/op
PASS
ok  	github.com/octu0/bp	7.147s

image.RGBA: sync.Pool vs ImageRGBAPool

$ go test -bench=BenchmarkImageRGBAPool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkImageRGBAPool/default/360-8         	   31308	     36206 ns/op	  925814 B/op	       3 allocs/op
BenchmarkImageRGBAPool/default/1080-8        	    4639	    821211 ns/op	 8282518 B/op	       3 allocs/op
BenchmarkImageRGBAPool/syncpool/360-8        	 1657608	       684.7 ns/op	      20 B/op	       1 allocs/op
BenchmarkImageRGBAPool/syncpool/1080-8       	 1635321	       696.2 ns/op	      56 B/op	       1 allocs/op
BenchmarkImageRGBAPool/imagepool/360-8       	 1000000	      1190 ns/op	     151 B/op	       3 allocs/op
BenchmarkImageRGBAPool/imagepool/1080-8      	 1000000	      1105 ns/op	     151 B/op	       3 allocs/op
PASS
ok  	github.com/octu0/bp	11.502s

io.Copy vs CopyIOPool.Copy Benchmark

CopyIOPool.Copy to reduce allocation of io.Copy

$ go test -bench=BenchmarkIoCopy -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkIoCopy-8                	  461892	      2637 ns/op	   32816 B/op	       3 allocs/op
BenchmarkIoCopyPoolDefault-8     	  619404	      1982 ns/op	   16608 B/op	       7 allocs/op
BenchmarkIoCopyPoolFixedSize-8   	 2858724	       410.9 ns/op	      48 B/op	       2 allocs/op
PASS
ok  	github.com/octu0/bp	4.126s

ioutil.ReadAll vs CopyIOPool.ReadAll Benchmark

similarly, CopyIOPool.ReadAll reduces allocation of io.ReadAll

$ go test -bench=BenchmarkIoReadAll -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkIoReadAllIoUtil-8          	    2628	    455815 ns/op	 5862972 B/op	      30 allocs/op
BenchmarkIoReadAllPoolDefault-8     	    3057	    378599 ns/op	 4063444 B/op	      13 allocs/op
BenchmarkIoReadAllPoolFixedSize-8   	    3180	    378923 ns/op	 4046892 B/op	       8 allocs/op
PASS
ok  	github.com/octu0/bp	3.718s

*time.Ticker: sync.Pool vs TickerPool

$ go test -bench=BenchmarkTickerPool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkTickerPool/default-8         	  114298	     10731 ns/op	     224 B/op	       4 allocs/op
BenchmarkTickerPool/syncpool-8        	  110748	     10863 ns/op	      32 B/op	       1 allocs/op
BenchmarkTickerPool/pool-8            	  110414	     10867 ns/op	      32 B/op	       1 allocs/op
PASS
ok  	github.com/octu0/bp	3.994s

*time.Timer: sync.Pool vs TimerPool

$ go test -bench=BenchmarkTimerPool -benchmem ./
goos: darwin
goarch: amd64
pkg: github.com/octu0/bp
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkTimerPool/default-8         	  115437	     10889 ns/op	     224 B/op	       4 allocs/op
BenchmarkTimerPool/syncpool-8        	  107302	     11099 ns/op	      32 B/op	       1 allocs/op
BenchmarkTimerPool/pool-8            	  106790	     11061 ns/op	      32 B/op	       1 allocs/op
PASS
ok  	github.com/octu0/bp	4.002s

License

Apache 2.0, see LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	DefaultMmapAlignment int = 8
)
View Source
const (
	Version string = "1.2.1"
)

Variables

View Source
var (
	ErrIOReadNagativeRead = errors.New("negative count from io.Read")
)

Functions

func AutoGrow added in v1.0.8

func AutoGrow(enable bool) optionFunc

func Copy added in v1.0.4

func Copy(dst io.Writer, src io.Reader) (int64, error)

func MaxBufSizeFactor

func MaxBufSizeFactor(factor float64) optionFunc

func MultiBufferPoolOption

func MultiBufferPoolOption(funcs ...optionFunc) multiBufferPoolOptionFunc

func MultiBufferPoolSize

func MultiBufferPoolSize(poolSize int, bufSize int) multiBufferPoolOptionFunc

func MultiBytePoolOption

func MultiBytePoolOption(funcs ...optionFunc) multiBytePoolOptionFunc

func MultiBytePoolSize

func MultiBytePoolSize(poolSize int, bufSize int) multiBytePoolOptionFunc

func MultiImagePoolOption

func MultiImagePoolOption(funcs ...optionFunc) multiImageBufferPoolOptionFunc

func MultiImagePoolSize

func MultiImagePoolSize(poolSize int, rect image.Rectangle) multiImageBufferPoolOptionFunc

func MultiMmapBytePoolOption added in v1.1.1

func MultiMmapBytePoolOption(funcs ...optionFunc) multiMmapBytePoolOptionFunc

func MultiMmapBytePoolSize added in v1.1.1

func MultiMmapBytePoolSize(poolSize int, bufSize int) multiMmapBytePoolOptionFunc

func Preload

func Preload(enable bool) optionFunc

func PreloadRate

func PreloadRate(rate float64) optionFunc

func ReadAll added in v1.0.4

func ReadAll(src io.Reader) ([]byte, error)

Types

type BufferPool

type BufferPool struct {
	// contains filtered or unexported fields
}

func NewBufferPool

func NewBufferPool(poolSize int, bufSize int, funcs ...optionFunc) *BufferPool

func (*BufferPool) Cap

func (b *BufferPool) Cap() int

func (*BufferPool) Get

func (b *BufferPool) Get() *bytes.Buffer

func (*BufferPool) GetRef

func (b *BufferPool) GetRef() *BufferRef

func (*BufferPool) Len

func (b *BufferPool) Len() int

func (*BufferPool) Put

func (b *BufferPool) Put(data *bytes.Buffer) bool

type BufferRef

type BufferRef struct {
	Buf *bytes.Buffer
	// contains filtered or unexported fields
}

func (*BufferRef) Buffer

func (b *BufferRef) Buffer() *bytes.Buffer

func (*BufferRef) Release

func (b *BufferRef) Release()

type BufioReaderGetPut added in v1.1.0

type BufioReaderGetPut interface {
	GetRef(io.Reader) *BufioReaderRef
	Get(io.Reader) *bufio.Reader
	Put(*bufio.Reader) bool
}

type BufioReaderPool

type BufioReaderPool struct {
	// contains filtered or unexported fields
}

func NewBufioReaderPool

func NewBufioReaderPool(poolSize int, funcs ...optionFunc) *BufioReaderPool

func NewBufioReaderSizePool

func NewBufioReaderSizePool(poolSize int, bufSize int, funcs ...optionFunc) *BufioReaderPool

func (*BufioReaderPool) Cap

func (b *BufioReaderPool) Cap() int

func (*BufioReaderPool) Get

func (b *BufioReaderPool) Get(r io.Reader) *bufio.Reader

func (*BufioReaderPool) GetRef

func (b *BufioReaderPool) GetRef(r io.Reader) *BufioReaderRef

func (*BufioReaderPool) Len

func (b *BufioReaderPool) Len() int

func (*BufioReaderPool) Put

func (b *BufioReaderPool) Put(br *bufio.Reader) bool

type BufioReaderRef

type BufioReaderRef struct {
	Buf *bufio.Reader
	// contains filtered or unexported fields
}

func (*BufioReaderRef) Reader

func (b *BufioReaderRef) Reader() *bufio.Reader

func (*BufioReaderRef) Release

func (b *BufioReaderRef) Release()

type BufioWriterGetPut added in v1.1.0

type BufioWriterGetPut interface {
	GetRef(io.Writer) *BufioWriterRef
	Get(io.Writer) *bufio.Writer
	Put(*bufio.Writer) bool
}

type BufioWriterPool

type BufioWriterPool struct {
	// contains filtered or unexported fields
}

func NewBufioWriterPool

func NewBufioWriterPool(poolSize int, funcs ...optionFunc) *BufioWriterPool

func NewBufioWriterSizePool

func NewBufioWriterSizePool(poolSize int, bufSize int, funcs ...optionFunc) *BufioWriterPool

func (*BufioWriterPool) Cap

func (b *BufioWriterPool) Cap() int

func (*BufioWriterPool) Get

func (b *BufioWriterPool) Get(w io.Writer) *bufio.Writer

func (*BufioWriterPool) GetRef

func (b *BufioWriterPool) GetRef(w io.Writer) *BufioWriterRef

func (*BufioWriterPool) Len

func (b *BufioWriterPool) Len() int

func (*BufioWriterPool) Put

func (b *BufioWriterPool) Put(bw *bufio.Writer) bool

type BufioWriterRef

type BufioWriterRef struct {
	Buf *bufio.Writer
	// contains filtered or unexported fields
}

func (*BufioWriterRef) Release

func (b *BufioWriterRef) Release()

func (*BufioWriterRef) Writer

func (b *BufioWriterRef) Writer() *bufio.Writer

type ByteGetPut added in v1.1.0

type ByteGetPut interface {
	GetRef() *ByteRef
	Get() []byte
	Put([]byte) bool
}

type BytePool

type BytePool struct {
	// contains filtered or unexported fields
}

func NewBytePool

func NewBytePool(poolSize int, bufSize int, funcs ...optionFunc) *BytePool

func (*BytePool) Cap

func (b *BytePool) Cap() int

func (*BytePool) Get

func (b *BytePool) Get() []byte

func (*BytePool) GetRef

func (b *BytePool) GetRef() *ByteRef

func (*BytePool) Len

func (b *BytePool) Len() int

func (*BytePool) Put

func (b *BytePool) Put(data []byte) bool

type ByteRef

type ByteRef struct {
	B []byte
	// contains filtered or unexported fields
}

func (*ByteRef) Bytes

func (b *ByteRef) Bytes() []byte

func (*ByteRef) Release

func (b *ByteRef) Release()

type BytesBufferGetPut added in v1.1.0

type BytesBufferGetPut interface {
	GetRef() *BufferRef
	Get() *bytes.Buffer
	Put(*bytes.Buffer) bool
}

type CopyIOPool added in v1.0.4

type CopyIOPool struct {
	// contains filtered or unexported fields
}

func NewCopyIOPool added in v1.0.4

func NewCopyIOPool(poolSize int, bufSize int, funcs ...optionFunc) *CopyIOPool

func (*CopyIOPool) Cap added in v1.0.4

func (c *CopyIOPool) Cap() int

func (*CopyIOPool) Copy added in v1.0.4

func (c *CopyIOPool) Copy(dst io.Writer, src io.Reader) (int64, error)

func (*CopyIOPool) Len added in v1.0.4

func (c *CopyIOPool) Len() int

func (*CopyIOPool) ReadAll added in v1.0.4

func (c *CopyIOPool) ReadAll(src io.Reader) ([]byte, error)

type ImageNRGBAGetPut added in v1.1.0

type ImageNRGBAGetPut interface {
	GetRef() *ImageNRGBARef
	Put([]byte) bool
}

type ImageNRGBAPool added in v1.0.9

type ImageNRGBAPool struct {
	ImageRGBAPool
}

func NewImageNRGBAPool added in v1.0.9

func NewImageNRGBAPool(poolSize int, rect image.Rectangle, funcs ...optionFunc) *ImageNRGBAPool

func (*ImageNRGBAPool) GetRef added in v1.0.9

func (b *ImageNRGBAPool) GetRef() *ImageNRGBARef

type ImageNRGBARef added in v1.0.9

type ImageNRGBARef struct {
	Img *image.NRGBA
	// contains filtered or unexported fields
}

func (*ImageNRGBARef) Image added in v1.0.9

func (b *ImageNRGBARef) Image() *image.NRGBA

func (*ImageNRGBARef) Release added in v1.0.9

func (b *ImageNRGBARef) Release()

type ImageRGBAGetPut added in v1.1.0

type ImageRGBAGetPut interface {
	GetRef() *ImageRGBARef
	Put([]byte) bool
}

type ImageRGBAPool

type ImageRGBAPool struct {
	// contains filtered or unexported fields
}

func NewImageRGBAPool

func NewImageRGBAPool(poolSize int, rect image.Rectangle, funcs ...optionFunc) *ImageRGBAPool

func (*ImageRGBAPool) Cap

func (b *ImageRGBAPool) Cap() int

func (*ImageRGBAPool) GetRef

func (b *ImageRGBAPool) GetRef() *ImageRGBARef

func (*ImageRGBAPool) Len

func (b *ImageRGBAPool) Len() int

func (*ImageRGBAPool) Put

func (b *ImageRGBAPool) Put(pix []byte) bool

type ImageRGBARef

type ImageRGBARef struct {
	Img *image.RGBA
	// contains filtered or unexported fields
}

func (*ImageRGBARef) Image

func (b *ImageRGBARef) Image() *image.RGBA

func (*ImageRGBARef) Release

func (b *ImageRGBARef) Release()

type ImageYCbCrGetPut added in v1.1.0

type ImageYCbCrGetPut interface {
	GetRef() *ImageYCbCrRef
	Put([]byte) bool
}

type ImageYCbCrPool

type ImageYCbCrPool struct {
	// contains filtered or unexported fields
}

func NewImageYCbCrPool

func NewImageYCbCrPool(poolSize int, rect image.Rectangle, sample image.YCbCrSubsampleRatio, funcs ...optionFunc) *ImageYCbCrPool

func (*ImageYCbCrPool) Cap

func (b *ImageYCbCrPool) Cap() int

func (*ImageYCbCrPool) GetRef

func (b *ImageYCbCrPool) GetRef() *ImageYCbCrRef

func (*ImageYCbCrPool) Len

func (b *ImageYCbCrPool) Len() int

func (*ImageYCbCrPool) Put

func (b *ImageYCbCrPool) Put(pix []byte) bool

func (*ImageYCbCrPool) UVStride added in v1.0.10

func (b *ImageYCbCrPool) UVStride(stride int)

func (*ImageYCbCrPool) YStride added in v1.0.10

func (b *ImageYCbCrPool) YStride(stride int)

type ImageYCbCrRef

type ImageYCbCrRef struct {
	Img *image.YCbCr
	// contains filtered or unexported fields
}

func (*ImageYCbCrRef) Image

func (b *ImageYCbCrRef) Image() *image.YCbCr

func (*ImageYCbCrRef) Release

func (b *ImageYCbCrRef) Release()

type MmapBytePool added in v1.1.0

type MmapBytePool struct {
	// contains filtered or unexported fields
}

func NewMmapBytePool added in v1.1.0

func NewMmapBytePool(poolSize, bufSize int, funcs ...optionFunc) *MmapBytePool

func (*MmapBytePool) Cap added in v1.1.0

func (b *MmapBytePool) Cap() int

func (*MmapBytePool) Get added in v1.1.0

func (b *MmapBytePool) Get() []byte

func (*MmapBytePool) GetRef added in v1.1.0

func (b *MmapBytePool) GetRef() *ByteRef

func (*MmapBytePool) Len added in v1.1.0

func (b *MmapBytePool) Len() int

func (*MmapBytePool) Put added in v1.1.0

func (b *MmapBytePool) Put(data []byte) bool

type MultiBufferPool

type MultiBufferPool struct {
	// contains filtered or unexported fields
}

func NewMultiBufferPool

func NewMultiBufferPool(funcs ...multiBufferPoolOptionFunc) *MultiBufferPool

func (*MultiBufferPool) Get

func (b *MultiBufferPool) Get(size int) *bytes.Buffer

func (*MultiBufferPool) GetRef

func (b *MultiBufferPool) GetRef(size int) *BufferRef

func (*MultiBufferPool) Put

func (b *MultiBufferPool) Put(data *bytes.Buffer) bool

type MultiBytePool

type MultiBytePool struct {
	// contains filtered or unexported fields
}

func NewMultiBytePool

func NewMultiBytePool(funcs ...multiBytePoolOptionFunc) *MultiBytePool

func (*MultiBytePool) Get

func (b *MultiBytePool) Get(size int) []byte

func (*MultiBytePool) GetRef

func (b *MultiBytePool) GetRef(size int) *ByteRef

func (*MultiBytePool) Put

func (b *MultiBytePool) Put(data []byte) bool

type MultiImageNRGBAPool added in v1.0.9

type MultiImageNRGBAPool struct {
	// contains filtered or unexported fields
}

func NewMultiImageNRGBAPool added in v1.0.9

func NewMultiImageNRGBAPool(funcs ...multiImageBufferPoolOptionFunc) *MultiImageNRGBAPool

func (*MultiImageNRGBAPool) GetRef added in v1.0.9

func (*MultiImageNRGBAPool) Put added in v1.0.9

func (b *MultiImageNRGBAPool) Put(pix []uint8, r image.Rectangle) bool

type MultiImageRGBAPool

type MultiImageRGBAPool struct {
	// contains filtered or unexported fields
}

func NewMultiImageRGBAPool

func NewMultiImageRGBAPool(funcs ...multiImageBufferPoolOptionFunc) *MultiImageRGBAPool

func (*MultiImageRGBAPool) GetRef

func (*MultiImageRGBAPool) Put

func (b *MultiImageRGBAPool) Put(pix []uint8, r image.Rectangle) bool

type MultiImageYCbCrPool

type MultiImageYCbCrPool struct {
	// contains filtered or unexported fields
}

func NewMultiImageYCbCrPool

func NewMultiImageYCbCrPool(sample image.YCbCrSubsampleRatio, funcs ...multiImageBufferPoolOptionFunc) *MultiImageYCbCrPool

func (*MultiImageYCbCrPool) GetRef

func (*MultiImageYCbCrPool) Put

func (b *MultiImageYCbCrPool) Put(pix []uint8, r image.Rectangle) bool

type MultiMmapBytePool added in v1.1.1

type MultiMmapBytePool struct {
	// contains filtered or unexported fields
}

func NewMultiMmapBytePool added in v1.1.1

func NewMultiMmapBytePool(funcs ...multiMmapBytePoolOptionFunc) *MultiMmapBytePool

func (*MultiMmapBytePool) Get added in v1.1.1

func (b *MultiMmapBytePool) Get(size int) []byte

func (*MultiMmapBytePool) GetRef added in v1.1.1

func (b *MultiMmapBytePool) GetRef(size int) *ByteRef

func (*MultiMmapBytePool) Put added in v1.1.1

func (b *MultiMmapBytePool) Put(data []byte) bool

type PoolSize added in v1.1.0

type PoolSize interface {
	Len() int
	Cap() int
}

type Ref

type Ref interface {
	Release()
	// contains filtered or unexported methods
}

type TickerGetPut added in v1.2.0

type TickerGetPut interface {
	GetRef(time.Duration) *TickerRef
	Get(time.Duration) *time.Ticker
	Put(*time.Ticker) bool
}

type TickerPool added in v1.2.0

type TickerPool struct {
	// contains filtered or unexported fields
}

func NewTickerPool added in v1.2.0

func NewTickerPool(poolSize int, funcs ...optionFunc) *TickerPool

func (*TickerPool) Cap added in v1.2.0

func (b *TickerPool) Cap() int

func (*TickerPool) Get added in v1.2.0

func (b *TickerPool) Get(dur time.Duration) *time.Ticker

func (*TickerPool) GetRef added in v1.2.0

func (b *TickerPool) GetRef(dur time.Duration) *TickerRef

func (*TickerPool) Len added in v1.2.0

func (b *TickerPool) Len() int

func (*TickerPool) Put added in v1.2.0

func (b *TickerPool) Put(t *time.Ticker) bool

type TickerRef added in v1.2.0

type TickerRef struct {
	T *time.Ticker
	// contains filtered or unexported fields
}

func (*TickerRef) Release added in v1.2.0

func (b *TickerRef) Release()

func (*TickerRef) Ticker added in v1.2.0

func (b *TickerRef) Ticker() *time.Ticker

type TimerGetPut added in v1.2.0

type TimerGetPut interface {
	GetRef(time.Duration) *TimerRef
	Get(time.Duration) *time.Timer
	Put(*time.Timer) bool
}

type TimerPool added in v1.2.0

type TimerPool struct {
	// contains filtered or unexported fields
}

func NewTimerPool added in v1.2.0

func NewTimerPool(poolSize int, funcs ...optionFunc) *TimerPool

func (*TimerPool) Cap added in v1.2.0

func (b *TimerPool) Cap() int

func (*TimerPool) Get added in v1.2.0

func (b *TimerPool) Get(dur time.Duration) *time.Timer

func (*TimerPool) GetRef added in v1.2.0

func (b *TimerPool) GetRef(dur time.Duration) *TimerRef

func (*TimerPool) Len added in v1.2.0

func (b *TimerPool) Len() int

func (*TimerPool) Put added in v1.2.0

func (b *TimerPool) Put(t *time.Timer) bool

type TimerRef added in v1.2.0

type TimerRef struct {
	T *time.Timer
	// contains filtered or unexported fields
}

func (*TimerRef) Release added in v1.2.0

func (b *TimerRef) Release()

func (*TimerRef) Ticker added in v1.2.0

func (b *TimerRef) Ticker() *time.Timer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL