{"id":15345684,"url":"https://github.com/git-hulk/routines","last_synced_at":"2025-04-14T23:36:18.389Z","repository":{"id":48534468,"uuid":"387087603","full_name":"git-hulk/routines","owner":"git-hulk","description":"Routines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic","archived":false,"fork":false,"pushed_at":"2024-09-09T07:29:36.000Z","size":18,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T11:42:44.646Z","etag":null,"topics":["go","golang","library","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/git-hulk.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}},"created_at":"2021-07-18T04:13:19.000Z","updated_at":"2024-09-09T07:29:39.000Z","dependencies_parsed_at":"2022-09-08T00:00:21.812Z","dependency_job_id":null,"html_url":"https://github.com/git-hulk/routines","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/git-hulk%2Froutines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Froutines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Froutines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Froutines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-hulk","download_url":"https://codeload.github.com/git-hulk/routines/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248980714,"owners_count":21193136,"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":["go","golang","library","pool"],"created_at":"2024-10-01T11:14:45.120Z","updated_at":"2025-04-14T23:36:18.365Z","avatar_url":"https://github.com/git-hulk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Routines\n[![Go Report Card](https://goreportcard.com/badge/github.com/git-hulk/routines)](https://goreportcard.com/report/github.com/git-hulk/routines) [![GitHub release](https://img.shields.io/github/tag/git-hulk/routines.svg?label=release)](https://github.com/git-hulk/routines/releases) [![GitHub release date](https://img.shields.io/github/release-date/git-hulk/routines.svg)](https://github.com/git-hulk/routines/releases) [![LICENSE](https://img.shields.io/github/license/git-hulk/routines.svg)](https://github.com/git-hulk/routines/blob/master/LICENSE) [![GoDoc](https://img.shields.io/badge/Godoc-reference-blue.svg)](https://godoc.org/github.com/git-hulk/routines) [![codecov](https://codecov.io/gh/git-hulk/routines/branch/master/graph/badge.svg?token=1O559OI069)](https://codecov.io/gh/git-hulk/routines) \n\nRoutines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic. It supports the sync process mode that would wait for the response, as well as the async mode, which would not wait for the response. The most commonly used scenario was to control the max concurrency when processing jobs.\n\n## Example 1: Process Tasks\nFor the full example, see: [examples/counter](examples/counter/main.go)\n \n```Go\ntype incrProcessor struct{}\n\nfunc (p *incrProcessor) Process(ctx context.Context, i interface{}) (interface{}, error) {\n   v := i.(*atomic.Int32)\n   v.Inc()\n   return v, nil\n}\n\nfunc main() {\n   // the pool would spawn 3 routines to process jobs and respawn\n   // a new one when panic\n   pool, err := routines.NewPool(3, \u0026incrProcessor{})\n   if err != nil {\n      panic(err)\n   }\n   // Start the routine pool\n   _ = pool.Start()\n\n   // Send the counter task to process in other routines\n   var wg sync.WaitGroup\n   v := atomic.NewInt32(0)\n   wg.Add(10)\n   for i := 0; i \u003c 10; i++ {\n      go func() {\n         defer wg.Done()\n         for j := 0; j \u003c 10; j++ {\n            _, _ = pool.Process(context.Background(), v)\n         }\n      }()\n   }\n   wg.Wait()\n\n   fmt.Println(\"Total: \", v.Load())\n   // Stop the routine pool and wait for all routines exited\n   _ = pool.Stop()\n   pool.Wait()\n}\n```\n\n## Example 2: Async Process Tasks\n\nFor the full example, see: [examples/counter](examples/async/main.go)\n\n```Go\ntype incrProcessor struct{}\n\nfunc (p *incrProcessor) Process(ctx context.Context, i interface{}) (interface{}, error) {\n   v := i.(*atomic.Int32)\n   v.Inc()\n   return v.Load(), nil\n}\n\nfunc main() {\n   // the pool would spawn 3 routines to process jobs and respawn\n   // a new one when panic\n   pool, err := routines.NewPool(3, \u0026incrProcessor{})\n   if err != nil {\n      panic(err)\n   }\n   // Start the routine pool\n   _ = pool.Start()\n\n   // Send the counter task to process in other routines\n   futures := make([]*routines.Future, 10)\n   v := atomic.NewInt32(0)\n   for i := 0; i \u003c 10; i++ {\n      futures[i], _ = pool.AsyncProcess(context.Background(), v)\n   }\n   for _, future := range futures {\n      val, err := future.Get(context.Background())\n      fmt.Println(val, err)\n   }\n\n   fmt.Println(\"Total: \", v.Load())\n   // Stop the routine pool and wait for all routines exited\n   _ = pool.Stop()\n   pool.Wait()\n}\n\n```\n\n## License\nRoutines is under the MIT license. See the [LICENSE](https://github.com/git-hulk/routines/blob/master/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-hulk%2Froutines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgit-hulk%2Froutines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-hulk%2Froutines/lists"}