Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Asynchronous in-memory workers for Go based projects

License

NotificationsYou must be signed in to change notification settings

mdouchement/workerpool

Repository files navigation

GoDocGo Report CardLicense

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

Usage

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)}

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. 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

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp