workerpool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0, MIT Imports: 3 Imported by: 1

README

fast-workerpool-go

fast-workerpool-go ports fasthttp FIFO worker pool

=== RUN   TestWorkerPool
--- PASS: TestWorkerPool (0.00s)
goos: darwin
goarch: amd64
pkg: github.com/detailyang/fast-worker-pool-go
BenchmarkWorkerPool-8        	 2505943	       423 ns/op	       8 B/op	       1 allocs/op
BenchmarkAntsWorkerPool-8    	 2428760	       436 ns/op	       8 B/op	       1 allocs/op
BenchmarkTunnyWorkerPool-8   	  521528	      2161 ns/op	      26 B/op	       2 allocs/op
BenchmarkSlaveWorkerPool-8   	 2424878	      1135 ns/op	       8 B/op	       0 allocs/op
PASS
ok  	github.com/detailyang/fast-worker-pool-go	34.960s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeJob(v interface{})
}

Handler represents the worker handler function

type HandlerFunc

type HandlerFunc func(v interface{})

HandlerFunc wraps the handler

func (HandlerFunc) ServeJob

func (h HandlerFunc) ServeJob(v interface{})

ServeJob serves the job

type WorkerPool

type WorkerPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WorkerPool holds the pool of worker

func New

func New(worker Handler, options ...WorkerPoolOptionSetterFunc) (*WorkerPool, error)

New returns the worker pool by options

func (*WorkerPool) Serve

func (wp *WorkerPool) Serve(v interface{}) bool

Serve dispatchs the worker to worker

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

Start starts the number of workers to wait workers

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop stops all workers

type WorkerPoolOptionSetterFunc

type WorkerPoolOptionSetterFunc func(*WorkerPool)

func WithWorkerPoolMaxIdleWorkerDuration

func WithWorkerPoolMaxIdleWorkerDuration(m time.Duration) WorkerPoolOptionSetterFunc

func WithWorkerPoolMaxWorkersCount

func WithWorkerPoolMaxWorkersCount(m int) WorkerPoolOptionSetterFunc

func WithWorkerPoolMustStop

func WithWorkerPoolMustStop() WorkerPoolOptionSetterFunc

Jump to

Keyboard shortcuts

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