workpool

package
v0.0.0-...-fab9456 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionFn

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

job 执行函数签名

type Job

type Job struct {
	Descriptor JobDescriptor
	ExecFn     ExecutionFn
	Args       interface{}
}

type JobDescriptor

type JobDescriptor struct {
	ID       string
	JobType  string
	Metadata map[string]interface{}
}

type Result

type Result struct {
	Value      interface{}
	Error      error
	Descriptor JobDescriptor
}

type Worker

type Worker struct {
	ID string
}

type WorkerPool

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

WorkerPool is a worker group that runs a number of workers at a configured concurrency.

func NewWorkerPool

func NewWorkerPool(workers int) *WorkerPool

NewWorkerPool initializes a new pool with the given number of Workers.

func (*WorkerPool) AddJob

func (p *WorkerPool) AddJob(jobs ...Job)

func (*WorkerPool) Done

func (p *WorkerPool) Done() <-chan struct{}

func (*WorkerPool) IsFinished

func (p *WorkerPool) IsFinished() bool

func (*WorkerPool) Release

func (p *WorkerPool) Release()

func (*WorkerPool) Results

func (p *WorkerPool) Results() <-chan Result

func (*WorkerPool) Run

func (p *WorkerPool) Run(ctx context.Context)

Jump to

Keyboard shortcuts

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