{"id":36455592,"url":"https://github.com/nikandfor/batch","last_synced_at":"2026-01-11T23:03:01.747Z","repository":{"id":212872986,"uuid":"732495511","full_name":"nikandfor/batch","owner":"nikandfor","description":"Reliable batches with ease.","archived":false,"fork":false,"pushed_at":"2025-04-01T01:30:56.000Z","size":79,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T02:29:02.711Z","etag":null,"topics":["batch","batching","concurrency","go","golang","parallelism","semaphore"],"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/nikandfor.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":"2023-12-16T21:31:15.000Z","updated_at":"2025-04-01T01:31:00.000Z","dependencies_parsed_at":"2024-01-17T02:19:00.032Z","dependency_job_id":"589cb4ba-6b46-42be-a4db-7f8a747a6c45","html_url":"https://github.com/nikandfor/batch","commit_stats":null,"previous_names":["nikandfor/batch"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/nikandfor/batch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikandfor%2Fbatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikandfor%2Fbatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikandfor%2Fbatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikandfor%2Fbatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikandfor","download_url":"https://codeload.github.com/nikandfor/batch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikandfor%2Fbatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28326166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T22:11:01.104Z","status":"ssl_error","status_checked_at":"2026-01-11T22:10:58.990Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["batch","batching","concurrency","go","golang","parallelism","semaphore"],"created_at":"2026-01-11T23:03:01.237Z","updated_at":"2026-01-11T23:03:01.739Z","avatar_url":"https://github.com/nikandfor.png","language":"Go","readme":"[![Documentation](https://pkg.go.dev/badge/nikand.dev/go/batch)](https://pkg.go.dev/nikand.dev/go/batch?tab=doc)\n[![Go workflow](https://github.com/nikandfor/batch/actions/workflows/go.yml/badge.svg)](https://github.com/nikandfor/batch/actions/workflows/go.yml)\n[![CircleCI](https://circleci.com/gh/nikandfor/batch.svg?style=svg)](https://circleci.com/gh/nikandfor/batch)\n[![codecov](https://codecov.io/gh/nikandfor/batch/tags/latest/graph/badge.svg)](https://codecov.io/gh/nikandfor/batch)\n[![Go Report Card](https://goreportcard.com/badge/nikand.dev/go/batch)](https://goreportcard.com/report/nikand.dev/go/batch)\n![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/nikandfor/batch?sort=semver)\n\n# batch\n\n`batch` is a library to make concurrent work batcheable and reliable.\nEach worker either has its work committed or gets an error.\n\n\u003e Hope is not a strategy. ([from Google SRE book](https://sre.google/sre-book/introduction/))\n\nNo more batch operations that add its data to a batch and go away hoping it would be committed.\n\nThis is all without timeouts, additional goroutines, allocations, and channels.\n\nThere is also [singleflight](./singleflight) lib in this module.\n\n## How it works\n\n* Each worker adds its work to a shared batch.\n* If there are no more workers in the queue the last one executes commit, the others wait.\n* Every worker in the batch gets the same result and error.\n\n## Usage\n\n```\n// General pattern is\n// Queue.In -\u003e Enter -\u003e defer Exit -\u003e add work to the batch -\u003e Commit/Cancel/panic/return\n\nvar sum int\n\nbc := batch.Controller[int]{\n\tCommitter: func(ctx context.Context) (int, error) {\n\t\t// commit sum\n\t\treturn sum, err\n\t},\n}\n\nfor j := 0; j \u003c N; j++ {\n\tgo func(j int) {\n\t\tbc.Queue().In() // let others know we are going to join\n\n\t\tdata := 1 // prepare data\n\n\t\tidx := bc.Enter(true)\n\t\tdefer bc.Exit()\n\n\t\tif idx == 0 { // we are first in the batch, reset it\n\t\t\tsum = 0\n\t\t}\n\n\t\tsum += data // add data to the batch\n\n\t\tres, err := bc.Commit(ctx)\n\t\tif err != nil { // works the same as we had independent commit in each goroutine\n\t\t\t_ = err\n\t\t}\n\n\t\t// batching is transparent for worker\n\t\t_ = res // res is the sum returned by Commit\n\t}(j)\n}\n```\n\nSee the all available options in [the doc](https://pkg.go.dev/nikand.dev/go/batch).\n\n`batch` is error- and panic-proof, meaning that user code can return an error or panic at any point.\nHowever, once all workers have exited the batch, its state is reset.\nExternal state, such as `sum` in this case, remains the caller's responsibility and must be kept consistent.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikandfor%2Fbatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikandfor%2Fbatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikandfor%2Fbatch/lists"}