worker_pool

package
v0.0.0-...-416ecfb Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 0 Imported by: 0

README

Worker pool

graph LR

subgraph Worker Pool
W1-->Task1
W2-->Task2
W3-->Task3
W4-->Task4
W5-->Task5
end
 
Task1-->Done
Task2-->Done
Task3-->Done
Task4-->Done
Task5-->Done
Done-->Result
TODO:
  • Use sync.Pool or sync.Cond to manage workers
  • Add Graceful Shutdown
References

Looking for Alternatives? Peek Here:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Value any
	Error error
}

type Task

type Task func() (any, error)

type WP

type WP interface {
	Push(task ...func()) error
}

type Worker

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

func NewWorker

func NewWorker(taskQueue <-chan Task, result chan<- Result) *Worker

type WorkerPool

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

func New

func New(workerNum int) *WorkerPool

func (*WorkerPool) Close

func (wp *WorkerPool) Close()

Close closes the task queue channel

func (*WorkerPool) Push

func (wp *WorkerPool) Push(task ...Task)

Jump to

Keyboard shortcuts

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