- Notifications
You must be signed in to change notification settings - Fork1
Asynchronous in-memory workers for Go based projects
License
NotificationsYou must be signed in to change notification settings
mdouchement/workerpool
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Asynchronous in-memory workers for Go based projects.
It is based onworkerpool, a lightweight workers solution, andtomb that handles clean goroutine tracking and termination.
This project aimed to provide the following points:
- Dynamic concurrency (expand and shrink the number of workers)
- Trackable background jobs
- Cancelable jobs
- Jobs' status
go get github.com/mdouchement/workerpool
package mainimport ("fmt""github.com/mdouchement/workerpool")funcmain() {// It is not mandatory to implement all *Func.job:=&workerpool.Job{// Triggered when the job's status changeOnStatusChangeFunc:func(j*workerpool.Job)error {fmt.Println("Status changed to:",j.Status())returnnil},// Before starting jobBeforeFunc:func(j*workerpool.Job)error {fmt.Println("Before starting job")returnnil},// Task to performActionFunc:func(j*workerpool.Job)error {fmt.Println("Starting job")returnnil},// When job is completedAfterFunc:func(j*workerpool.Job)error {fmt.Println("After job")returnnil},// Triggered when workerpool.Cancel("job_id")// You can use j.Context() to forward cancellation signal.CancelFunc:func(j*workerpool.Job)error {fmt.Println("Execute cleanup function")returnnil},// Triggered when an error or panic occurred.ErrHandler:func(j*workerpool.Job,errerror,panicbool) {// Do something with the error (and j.Context()).},}id:=workerpool.Send(job)fmt.Println("Job id:",id)}
MIT
All PRs are welcome.
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
As possible, run the following commands to format and lint the code:
# Formatfind. -name'*.go' -not -path'./vendor*' -exec gofmt -s -w {}\;# Lintgometalinter --config=gometalinter.json ./...
About
Asynchronous in-memory workers for Go based projects
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.