Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 978 Bytes

README.md

File metadata and controls

44 lines (34 loc) · 978 Bytes

Simple concurrent worker pool in GO

Go Reference

Simple implement concurrent worker pool & queue in go. You can test it by simple command below.

Clone the project

$ git clone https://github.com/lequocbinh04/go-workerpool
$ cd go-workerpool

Build project

$ go build

Run

$ ./worker-pool

Then you can go to https://localhost:8080/test?msg=Hello worker and check log.

Apply in your project

You can copy workerpool folder to your project. Init worker pool:

dispatch := workerpool.NewDispatcher(10) // start 10 workers
dispatch.Run()
workerpool.InitJobQueue()

and add job to pool:

job := workerpool.NewJob(func(ctx context.Context) error {
    // Simple job, replace it :D
    time.Sleep(time.Second)
    log.Println("I am job, message: ", msg)
    return nil
})
workerpool.JobQueue <- job