How it works
Its a plain simple goroutine pool.
Run the example
This will run the example of how havuz works.
go run examples/main.go
How many workers you like to have?
WithWorkerCount(workerCount int) ConfigParam
What is the pool capacity you like to have?
WithPoolCapacity(poolCapacity int) ConfigParam
When should havuz clean up the idle workers?
WithIdleWorkerTimeout(idleWorkerTimeout time.Duration) ConfigParam
Do you have a context to shutdown goroutine pool?
WithContext(parentCtx context.Context) ConfigParam
How to initiate havuz?
havuz.New(configs ...ConfigParam) *WorkerPool
Eg,
havuz.New(
WithPoolCapacity(poolCapacity int),
WithWorkerCount(workerCount int)
)
How to send a task? (Tries to submit the task, if the queue is full then it drops the task)
func (wp *WorkerPool) TrySubmit(task func()) bool
How to send a task forcefully? (Tries to submit the task, if the queue is full then it will block till its sent)
func (wp *WorkerPool) MustSubmit(task func()) bool
You can gracefully shutdown the pool with this.
func (wp *WorkerPool) Shutdown()
You can set log handler
func (wp *WorkerPool) SetLogHandler(f func(msg string))
You can set error handler
func (wp *WorkerPool) SetErrorHandler(f func(err error))