worker

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is a buffered worker pool

func NewPool

func NewPool(maxWorker, poolSize int) *Pool

func (*Pool) Shutdown

func (p *Pool) Shutdown(ctx context.Context) error

func (*Pool) Submit

func (p *Pool) Submit(ctx context.Context, tf TaskFunc, concurrence int) TaskResult

type TaskFunc

type TaskFunc func() error

type TaskResult

type TaskResult interface {
	// get error if task failed.
	Err() error
	// wait for task done.
	Wait()
	// get task status.
	Status() TaskStatus
	// kill task.
	Kill()
}

TaskResult is a manager of submitted task.

type TaskStatus

type TaskStatus int

TaskStatus is the status of task. TaskStatus implements TaskResult interface.

const (
	// TaskStatusEnqueue means task is enqueued.
	TaskStatusEnqueue TaskStatus = iota
	// TaskStatusRunning means task is running.
	TaskStatusRunning
	// TaskStatusDone means task is done.
	TaskStatusDone
	// TaskStatusKilled means task is killed.
	TaskStatusKilled
	// TaskStatusError means task error.
	TaskStatusError
	// TaskStatusQueueFull means task queue is full.
	TaskStatusQueueFull
	// TaskStatusTooManyWorker means task concurrence is greater then worker pool max worker count.
	TaskStatusTooManyWorker
	// TaskStatusPoolClosed means task run worker pool closed.
	TaskStatusPoolClosed
)

func (TaskStatus) Err

func (t TaskStatus) Err() error

func (TaskStatus) Error

func (t TaskStatus) Error() string

func (TaskStatus) Kill

func (t TaskStatus) Kill()

func (TaskStatus) Status

func (t TaskStatus) Status() TaskStatus

func (TaskStatus) String

func (t TaskStatus) String() string

func (TaskStatus) Wait

func (t TaskStatus) Wait()

Jump to

Keyboard shortcuts

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