{"id":22696718,"url":"https://github.com/vallahaye/go-batcher","last_synced_at":"2025-04-13T04:35:17.935Z","repository":{"id":231086974,"uuid":"780858144","full_name":"vallahaye/go-batcher","owner":"vallahaye","description":"Zero dependency generic Golang batcher","archived":false,"fork":false,"pushed_at":"2024-10-26T10:10:14.000Z","size":17,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T21:23:09.429Z","etag":null,"topics":["batch-processing","generics","go","golang"],"latest_commit_sha":null,"homepage":"https://go.vallahaye.net/batcher","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vallahaye.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":"2024-04-02T09:42:51.000Z","updated_at":"2025-02-05T14:00:46.000Z","dependencies_parsed_at":"2024-04-30T18:30:36.504Z","dependency_job_id":"6a7849c0-01ba-4153-b4b6-409f443ebeb7","html_url":"https://github.com/vallahaye/go-batcher","commit_stats":null,"previous_names":["vallahaye/go-batcher"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallahaye%2Fgo-batcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallahaye%2Fgo-batcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallahaye%2Fgo-batcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallahaye%2Fgo-batcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vallahaye","download_url":"https://codeload.github.com/vallahaye/go-batcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665157,"owners_count":21142118,"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":["batch-processing","generics","go","golang"],"created_at":"2024-12-10T05:10:03.709Z","updated_at":"2025-04-13T04:35:17.913Z","avatar_url":"https://github.com/vallahaye.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Batcher\n\n[![Go Reference](https://pkg.go.dev/badge/go.vallahaye.net/batcher.svg)](https://pkg.go.dev/go.vallahaye.net/batcher)\n[![Go Report Card](https://goreportcard.com/badge/go.vallahaye.net/batcher)](https://goreportcard.com/report/go.vallahaye.net/batcher)\n\nGo Batcher provides a generic and versatile implementation of a batching algorithm for Golang, with no third-party dependencies. The algorithm can be constrained in [space](https://pkg.go.dev/go.vallahaye.net/batcher#WithMaxSize) and [time](https://pkg.go.dev/go.vallahaye.net/batcher#WithTimeout), with a simple yet robust API, enabling developers to easily incorporate batching into their live services.\n\n### Goals\n\n- Easy to use and minimal API surface area\n- Efficient use of resources, i.e. reuse of memory and good use of goroutines parking behavior\n- Well-tested and documented\n\n### Non-goals\n\n- Provide helper functions to interface Go Batcher with other software solutions (for example, connecting Go Batcher to a distributed task/job framework)\n\n## Example\n\n```go\n// Define a commit function.\ncommitFn := func(ctx context.Context, ops batcher.Operations[string, string]) {\n  // Watch the context's Done channel to know when the batching process gets interrupted.\n  //\n  // Do something with the batch of operations.\n  // See [Operations.SetError] to signal an error to all operations.\n  for _, op := range ops {\n    // See [Operation.SetResult] and [Operation.SetError] to signal individual results and errors.\n  }\n}\n\n// Create a batcher committing a batch every 10 operations.\nb := batcher.New(commitFn, batcher.WithMaxSize[string, string](10))\n\n// Run the batcher in the background. Cancel the context to interrupt the batching process.\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n\ngo func() {\n  b.Batch(ctx)\n}()\n\nhttp.HandleFunc(\"/send\", func(w http.ResponseWriter, r *http.Request) {\n  // Send a value to the batcher.\n  op, err := b.Send(r.Context(), r.FormValue(\"value\"))\n  if err != nil {\n    // Do something with the error.\n  }\n\n  // Get the operation's result.\n  result, err := op.Wait(r.Context())\n  if err != nil {\n    // Do something with the error.\n  }\n\n  // Do something with the operation's result.\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallahaye%2Fgo-batcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvallahaye%2Fgo-batcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallahaye%2Fgo-batcher/lists"}