{"id":41399911,"url":"https://github.com/ynori7/workerpool","last_synced_at":"2026-01-23T13:05:44.501Z","repository":{"id":125457214,"uuid":"258431581","full_name":"ynori7/workerpool","owner":"ynori7","description":"The worker pool library abstracts the setup around creating worker pools, so all you need to take care of is the actual business logic.","archived":false,"fork":false,"pushed_at":"2025-07-23T06:08:09.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-23T08:17:44.615Z","etag":null,"topics":["go","worker-pool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ynori7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-24T06:55:02.000Z","updated_at":"2025-07-23T06:08:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"7daf6cb6-76d1-4526-8770-702690e90fdd","html_url":"https://github.com/ynori7/workerpool","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ynori7/workerpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynori7%2Fworkerpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynori7%2Fworkerpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynori7%2Fworkerpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynori7%2Fworkerpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ynori7","download_url":"https://codeload.github.com/ynori7/workerpool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynori7%2Fworkerpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28692738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T11:01:27.039Z","status":"ssl_error","status_checked_at":"2026-01-23T11:00:26.909Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","worker-pool"],"created_at":"2026-01-23T13:05:44.411Z","updated_at":"2026-01-23T13:05:44.486Z","avatar_url":"https://github.com/ynori7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Worker Pool [![GoDoc](https://godoc.org/github.com/ynori7/workerpool?status.png)](https://godoc.org/github.com/ynori7/workerpool) [![Build Status](https://travis-ci.org/ynori7/workerpool.svg?branch=master)](https://travis-ci.com/github/ynori7/workerpool) [![Coverage Status](https://coveralls.io/repos/github/ynori7/workerpool/badge.svg?branch=master)](https://coveralls.io/github/ynori7/workerpool?branch=master) [![Go Report Card](https://goreportcard.com/badge/ynori7/workerpool)](https://goreportcard.com/report/github.com/ynori7/workerpool)\nThe worker pool library abstracts the setup around creating worker pools, so all\nyou need to take care of is the actual business logic.\n\n# How it works\nThe work will be evenly distributed to N workers which process in parallel. Successful\nresponses are passed back through a success channel and errors through an error channel.\nA callback can be specified to provide behavior for successes and errors. The actual logic\nof the worker is specified by providing a function which handles the logic and returns either\na result or an error.\n\n# Usage\n\nThe worker pool is defined as follow:\n\n```go\nfunc NewWorkerPool(\n\tworkerCount int,\n\tonSuccess SuccessFunc,\n\tonError ErrorFunc,\n\tdoWork DoWorkFunc,\n)\n```\n- The workerCount is the number of workers which will process jobs in parallel.\n- onSuccess is the callback which is called for each successful result\n- onError is the callback which is called for each failed result\n- doWork is the function which is called to process each job. This is the part \nwhich works concurrently.\n\nHere is a short example:\n\n```go\nsuccesses := make([]int, 0)\n\nworkerPool := NewWorkerPool(\n    func(result interface{}) { //On success\n        r := result.(int)\n        successes = append(successes, r) \n    },\n    func(err error) { //On error\n        log.Println(err.Error())\n    },\n    func(job interface{}) (result interface{}, err error) { //Do work\n        j := job.(int)\n        if j \u003e 4 {\n            return nil, fmt.Errorf(\"number too big: %d\", j)\n        }\n        return j, nil\n    })\n\n//Do the work\nif err := workerPool.Work(\n\t    ctx,\n\t    3, //The number of workers which should work in parallel\n\t    []int{1, 2, 3, 4, 5, 6, 7}, //The items to be processed\n\t); err != nil {\n    log.Println(err.Error())\n}\n```\n\n### Cancelling the jobs\n\nSometimes you may want to stop processing early if, for example, enough results have \nbeen found. This can be done by canceling the context passed into the worker pool:\n\n```go\nctx, cancel := context.WithCancel(context.Background())\n\nsuccesses := make([]int, 0)\n\nworkerPool := NewWorkerPool(\n    3, //The number of workers which should work in parallel\n    func(result interface{}) { //On success\n        r := result.(int)\n        successes = append(successes, r) \n        if len(successes) \u003e 3 {\n            cancel() //we have enough results\n        }\n    },\n    func(err error) { //On error\n        log.Println(err.Error())\n    },\n    func(job interface{}) (result interface{}, err error) { //Do work\n        j := job.(int)\n        if j \u003e 4 {\n            return nil, fmt.Errorf(\"number too big: %d\", j)\n        }\n        return j, nil\n    })\n\n//Do the work\nif err := workerPool.Work(ctx, 3, []int{1, 2, 3, 4, 5, 6, 7}); err != nil {\n    log.Println(err.Error())\n}\n```\nIn the above code, once 3 successes have been found, it will signal the worker pool\nto \nstop processing futher.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynori7%2Fworkerpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fynori7%2Fworkerpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynori7%2Fworkerpool/lists"}