{"id":19733799,"url":"https://github.com/luca-moser/pool","last_synced_at":"2025-02-27T20:53:07.995Z","repository":{"id":57592034,"uuid":"94789010","full_name":"luca-moser/pool","owner":"luca-moser","description":"worker pool implementation for Go.","archived":false,"fork":false,"pushed_at":"2017-06-28T19:19:39.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-10T18:21:59.488Z","etag":null,"topics":["concurrency","go","golang","parallelization","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/luca-moser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-19T14:59:08.000Z","updated_at":"2017-07-18T19:27:58.000Z","dependencies_parsed_at":"2022-08-30T05:21:00.663Z","dependency_job_id":null,"html_url":"https://github.com/luca-moser/pool","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luca-moser%2Fpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luca-moser%2Fpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luca-moser%2Fpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luca-moser%2Fpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luca-moser","download_url":"https://codeload.github.com/luca-moser/pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241058966,"owners_count":19902293,"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":["concurrency","go","golang","parallelization","worker-pool"],"created_at":"2024-11-12T00:33:52.774Z","updated_at":"2025-02-27T20:53:07.969Z","avatar_url":"https://github.com/luca-moser.png","language":"Go","readme":"# Worker Pool [![Build Status](https://travis-ci.org/luca-moser/pool.svg?branch=master)](https://travis-ci.org/luca-moser/pool)\n\nA simple worker pool which receives jobs and distributes them to workers.\nWorkers can send errors and results back to the pool creator through channels or handler functions.\n\n## Usage\n```go\n// new pool with 8 worker goroutines\nworkerPool, err := pool.NewWorkerPool(8)\nif err != nil {\n    ...\n}\n\nconst iterationCount = 100\nvar processed int\n\n// called when a result was produced by a worker\nresultHandler := func(result interface{}) {\n    // no mutex needed here as the resultHandler is not called concurrently\n    processed += result.(int)\n}\n\n// called when an error was produced by a worker\nerrorHandler := func(err error) {\n    t.Fatal(err)\n}\n\n// define the handler functions on the pool\nworkerPool.AddHandlers(resultHandler, errorHandler)\n\n// OR discard any results and errors (not to be used with AddHandlers simultaneously(!))\n// workerPool.Discard()\n\n// add jobs to the pool\nfor i := 0; i \u003c iterationCount; i++ {\n    // add a function to the pool for execution which returns a result or error\n    workerPool.AddFuncWithResult(f)\n    \n    // OR a function which does not return anything, except maybe an error\n    // workerPool.AddFunc(func() error {})\n    \n    // OR a job\n    // workerPool.AddJob(Job{\n    //     Function: func(args ...interface{}) (interface{}, error) {\n    //         return nil, nil\n    //     },\n    //     Arguments: []interface{}{1,2,3,4},\n    // })\n}\n\n// wait for the amount of jobs to complete\nworkerPool.Wait(iterationCount)\n\n// free up goroutines and close channels\nworkerPool.Stop()\n\n// returns information about each worker's processed jobs\nworkerPool.Stats()\n```\n\n### Job results and errors\nIt's important that the error and result channels are being actively used or discarded.\nThis can be achieved by using the `Errors()` and `Results()` functions which give you channels\nto listen for or `DiscardErrors()` and `DiscardResults()` or `Discard()` (errors and results combined).\nBy using the `AddHandlers` function handlers can be defined which are executed as soon as results and errors are\nproduced by workers.\n\n### Other\nIf a worker panics during the execution of the job, an error will be generated, the worker will then resume normally.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluca-moser%2Fpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluca-moser%2Fpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluca-moser%2Fpool/lists"}