Skip to content

Simple implement concurrent worker pool & queue in go

Notifications You must be signed in to change notification settings

lequocbinh04/go-workerpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple implement concurrent worker pool & queue in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages