gofast

package module
v0.0.0-...-46d0305 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: Apache-2.0 Imports: 3 Imported by: 1

README

gofast

A worker pool written in Golang

Usage

os.Setenv("MAX_WORKER", "20")
os.Setenv("MAX_QUEUE", "100")

d := NewDispatcher()
d.Run(func(job Job) { time.Sleep(1 * time.Second) })

for i := 0; i < 100; i++ {
	job := Job{Payload: "job" + strconv.Itoa(i)}
	d.JobQueue <- job
}
  

Benchmark

BenchmarkNewDispatcher-8 500000 4499 ns/op 557 B/op 4 allocs/op PASS ok github.com/lvsiquan/gofast 2.412s

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxQueue = os.Getenv("MAX_QUEUE")
View Source
var MaxWorker = os.Getenv("MAX_WORKER")

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	WorkerPool chan chan Job
	MaxWorker  int
	JobQueue   chan Job
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher() *Dispatcher

func (*Dispatcher) Run

func (d *Dispatcher) Run(handler JobHandler)

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

type Job

type Job struct {
	Payload interface{}
}

type JobHandler

type JobHandler func(job Job)

type Worker

type Worker struct {
	Name       string
	WorkerPool chan chan Job
	JobChannel chan Job
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(workerpool chan chan Job, handler JobHandler, workerNo int) Worker

Jump to

Keyboard shortcuts

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