concurrency

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const LoopTimeout = time.Second * 20
View Source
const SleepTime = time.Microsecond * 5

Variables

View Source
var DefaultWorkerCount = runtime.NumCPU()

DefaultWorkerCount default workers count, depend on runtime cpu value

Functions

This section is empty.

Types

type ExecutionFn

type ExecutionFn func(ctx context.Context, args interface{}) (interface{}, error)

type Result

type Result struct {
	Value      interface{}
	Err        error
	Descriptor TaskDescriptor
}

type Task

type Task struct {
	Args       interface{}
	ExecFn     ExecutionFn
	Descriptor TaskDescriptor
}

type TaskDescriptor

type TaskDescriptor struct {
	Metadata TaskMetadata
	TaskType TaskType
	ID       TaskID
}

type TaskID

type TaskID uint32

type TaskMetadata

type TaskMetadata map[string]interface{}

type TaskType

type TaskType string

type WorkerPool

type WorkerPool struct {
	Tasks                    chan Task   // input tasks to work parallel following order
	Results                  chan Result // output result channel, results will be in order as per input task order
	WorkerPoolName           string
	WorkerStopChannel        []chan bool   // worker stop channel
	WorkerInputReadyChannel  []chan bool   // worker input ready channel
	WorkerOutputReadyChannel []chan bool   // worker output ready channel
	LoopTimeOut              time.Duration // read loop timeout limit, default 2 seconds
	WorkersCount             int
	TasksCount               int
}

func New

func New(workerCount, tasksCount int, workerPoolName string) WorkerPool

func NewWithLoopTimeOut

func NewWithLoopTimeOut(workerCount, tasksCount int, workerPoolName string, loopTimeOut time.Duration) WorkerPool

func (WorkerPool) GenerateFrom

func (wp WorkerPool) GenerateFrom(bulkTasks []Task)

func (WorkerPool) Run

func (wp WorkerPool) Run(ctx context.Context)

func (WorkerPool) StopWorkers

func (wp WorkerPool) StopWorkers()

Jump to

Keyboard shortcuts

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