pool

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GetByte retrieves a byte slice but uses the global pool
	GetByte = builtinPool.Get
	// PutByte returns a byte slice but uses the global pool
	PutByte = builtinPool.Put
)

Functions

This section is empty.

Types

type BytePool

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

Pool consists of 32 sync.Pool, representing byte slices of length from 0 to 32 in powers of 2.

func (*BytePool) Get

func (p *BytePool) Get(size int) (buf []byte)

Get retrieves a byte slice of the length requested by the caller from pool or allocates a new one.

func (*BytePool) Put

func (p *BytePool) Put(buf []byte)

Put returns the byte slice to the pool.

type FixedGoroutinePool added in v1.2.1

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

FixedGoroutinePool 固定数量的协程池

func NewFixedGoroutinePool added in v1.2.1

func NewFixedGoroutinePool(options ...fixedOption) *FixedGoroutinePool

func (*FixedGoroutinePool) Schedule added in v1.2.1

func (pool *FixedGoroutinePool) Schedule(task func())

func (*FixedGoroutinePool) Stop added in v1.2.1

func (pool *FixedGoroutinePool) Stop()

type FixedOptions added in v1.2.1

type FixedOptions struct {
	Num   int  // 协程数
	Block bool // 任务已满时是否需要阻塞
}

type GoroutinePool added in v1.2.1

type GoroutinePool interface {
	// Schedule 调度worker执行任务
	Schedule(task func())

	// Stop 停止工作
	Stop()
}

type Option added in v1.2.1

type Option func(options *Options)

type Options added in v1.2.1

type Options struct {
	Max     int32 // maximum number of workers
	Idle    int   // idle number of workers
	Block   bool
	Timeout time.Duration // quit time for worker
}

type Provider added in v1.2.1

type Provider[Object any] interface {
	Acquire() Object
	Release(obj Object)
}

Provider represents a object provider

func NewSyncPoolProvider added in v1.2.1

func NewSyncPoolProvider[Object any](constructor func() interface{}) Provider[Object]

type ScalableGroutinePool added in v1.2.1

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

func NewGoroutinePool added in v1.2.1

func NewGoroutinePool(opts ...Option) *ScalableGroutinePool

func (*ScalableGroutinePool) Schedule added in v1.2.1

func (p *ScalableGroutinePool) Schedule(task func())

Schedule 执行任务

func (*ScalableGroutinePool) Stop added in v1.2.1

func (p *ScalableGroutinePool) Stop()

Stop 停止协程池

type SyncPoolProvider added in v1.2.1

type SyncPoolProvider[Object any] struct {
	// contains filtered or unexported fields
}

func (*SyncPoolProvider[Object]) Acquire added in v1.2.1

func (provider *SyncPoolProvider[Object]) Acquire() Object

func (*SyncPoolProvider[Object]) Release added in v1.2.1

func (provider *SyncPoolProvider[Object]) Release(obj Object)

type Worker added in v1.2.1

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

func NewWorker added in v1.2.1

func NewWorker(cap int, beforeCloseCallback func(), afterCallback func(w *Worker)) *Worker

func (*Worker) Stop added in v1.2.1

func (w *Worker) Stop()

stop this worker.

func (*Worker) Submit added in v1.2.1

func (w *Worker) Submit(task f, block bool)

Submit sends a task to this worker.

Jump to

Keyboard shortcuts

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