{"id":22018141,"url":"https://github.com/rvflash/workr","last_synced_at":"2025-03-23T09:27:43.430Z","repository":{"id":57618212,"uuid":"387231686","full_name":"rvflash/workr","owner":"rvflash","description":"Another Golang worker pool","archived":false,"fork":false,"pushed_at":"2023-04-16T18:44:34.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-28T16:16:29.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/rvflash.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":"2021-07-18T17:24:44.000Z","updated_at":"2023-04-16T18:42:42.000Z","dependencies_parsed_at":"2024-06-19T01:28:36.439Z","dependency_job_id":null,"html_url":"https://github.com/rvflash/workr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fworkr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fworkr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fworkr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fworkr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvflash","download_url":"https://codeload.github.com/rvflash/workr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245081336,"owners_count":20557815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-30T05:10:07.778Z","updated_at":"2025-03-23T09:27:43.405Z","avatar_url":"https://github.com/rvflash.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workr, another Golang worker pool\n\n[![GoDoc](https://godoc.org/github.com/rvflash/workr?status.svg)](https://godoc.org/github.com/rvflash/workr)\n[![Build Status](https://github.com/rvflash/workr/workflows/build/badge.svg)](https://github.com/rvflash/workr/actions?workflow=build)\n[![Code Coverage](https://codecov.io/gh/rvflash/workr/branch/main/graph/badge.svg)](https://codecov.io/gh/rvflash/workr)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rvflash/workr)](https://goreportcard.com/report/github.com/rvflash/workr)\n\n`workr` provides synchronization, error propagation, context cancellation and execution details \nfor groups of tasks running in parallel with a limited number of goroutines.\nThis number is by default fixed by the number of CPU.\n\nIt provides an interface similar to `sync/errgroup` to manage a group of subtasks.\n\n## Install\n\ngo 1.20 is the minimum required version due to the usage of `errors.Join`.\n\n```bash\n$ go get -u github.com/rvflash/workr\n```\n\n## Example\n\nSimple use case that returns the first error occurred.\n\n```go\n    g := new(workr.Group)\n    g.Go(func() error {\n        return nil\n    })\n    err := g.Wait()\n````\n\nA more advanced one that returns all errors that occurred, not only the first one.\n\n```go\n    var (\n        g   = workr.New(workr.ReturnAllErrors())\n        ctx = context.Background()\n    )\n    g.Go(func() error {\n        return doSomething(ctx)\n    })\n    g.Go(func() error {\n        return doSomethingElse(ctx)\n    })\n    err := g.Wait()\n````\n\nIt also provides a method `WaitAndReturn` to get details on each task done and \nfunctions to list those that were successful or `SuccessfulResult` not `FailedResult`.\n\nBy creating the worker with a context, the first task on error will cancel it and so, \nall tasks using it are also cancelled.\n\n```go\n    oops := errors.New(\"oops\")\n\t\n    g, ctx := workr.WithContext(context.Background(), workr.SetPoolSize(2))\n    g.Go(\n\t\tfunc() error {\n            return oops\n        }, \n\t\tworkr.ID(1), \n\t\tworkr.SkipError(oops),\n\t)\n    g.Go(\n\t\tfunc() error {\n            return doSomething(ctx)\n        },\n\t\tworkr.SetID(2),\n\t)\n    res, err := g.WaitAndReturn()\n    if err != nil {\n        // No error expected\n    }\n    log.Println(workr.SuccessfulResult(res).IDList())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvflash%2Fworkr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvflash%2Fworkr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvflash%2Fworkr/lists"}