workers

package module
v1.3.0 Latest Latest
Warning

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

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

README

WORKERS

workers pool for Golang

Install

go get -u github.com/aacfactory/workers

Usage

Create worker command handler

type Handler struct {}

func (h *Handler) Handle(command interface{}) {
    // todo: handle command
}

New workers and execute command

workers := workers.New(&Handler{})


if ok := workers.Execute(struct{}); !ok {
    // todo: handle 'no workers remain' or 'closed'
}

workers.Close()

Benchmark

Handler used in benchmark is sleeping 50 millisecond as handling command.

goos: windows
goarch: amd64
pkg: github.com/aacfactory/workers
cpu: AMD Ryzen 9 3950X 16-Core Processor
BenchmarkNewWorkers
    worker_benchmark_test.go:37: total 1 accepted 1
    worker_benchmark_test.go:37: total 100 accepted 100
    worker_benchmark_test.go:37: total 10000 accepted 10000
    worker_benchmark_test.go:37: total 266420 accepted 266420
    worker_benchmark_test.go:37: total 834958 accepted 834958
    worker_benchmark_test.go:37: total 1104766 accepted 1104766
BenchmarkNewWorkers-32           1104766               953.7 ns/op            25
 B/op          1 allocs/op
PASS

Thanks

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler added in v1.3.0

type Handler interface {
	Handle(payload interface{})
}

type Option

type Option func(*Options) error

func Concurrency added in v1.3.0

func Concurrency(concurrency int) Option

func WorkerMaxIdleDuration added in v1.3.0

func WorkerMaxIdleDuration(d time.Duration) Option

type Options added in v1.1.0

type Options struct {
	Concurrency           int
	WorkerMaxIdleDuration time.Duration
}

type Workers

type Workers interface {
	Execute(command interface{}) (ok bool)
	Close()
}

func New added in v1.2.0

func New(handler Handler, options ...Option) (w Workers)

Jump to

Keyboard shortcuts

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