{"id":13413046,"url":"https://github.com/nar10z/go-accumulator","last_synced_at":"2026-01-12T01:48:47.319Z","repository":{"id":153796517,"uuid":"625825738","full_name":"nar10z/go-accumulator","owner":"nar10z","description":"Solution for accumulation of events and their subsequent processing.","archived":false,"fork":false,"pushed_at":"2025-09-04T19:12:56.000Z","size":170,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-02T10:33:19.631Z","etag":null,"topics":["accumulator","batch","go","golang","golang-tools","goroutines","utility"],"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/nar10z.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-10T07:22:55.000Z","updated_at":"2025-09-09T18:53:02.000Z","dependencies_parsed_at":"2024-05-11T11:39:04.880Z","dependency_job_id":"4f469552-1698-4c85-9d42-9d6c4e57ecda","html_url":"https://github.com/nar10z/go-accumulator","commit_stats":null,"previous_names":["nar10z/go-collector","nar10z/go-events-accumulator"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/nar10z/go-accumulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nar10z%2Fgo-accumulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nar10z%2Fgo-accumulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nar10z%2Fgo-accumulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nar10z%2Fgo-accumulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nar10z","download_url":"https://codeload.github.com/nar10z/go-accumulator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nar10z%2Fgo-accumulator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"ssl_error","status_checked_at":"2026-01-12T00:36:15.229Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["accumulator","batch","go","golang","golang-tools","goroutines","utility"],"created_at":"2024-07-30T20:01:32.779Z","updated_at":"2026-01-12T01:48:47.304Z","avatar_url":"https://github.com/nar10z.png","language":"Go","funding_links":[],"categories":["Goroutines"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"readme":"# go-accumulator\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/nar10z/go-accumulator.svg)](https://pkg.go.dev/github.com/nar10z/go-accumulator)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nar10z/go-accumulator)](https://goreportcard.com/report/github.com/nar10z/go-accumulator)\n[![codecov](https://codecov.io/gh/nar10z/go-accumulator/graph/badge.svg?token=56NA65VT60)](https://codecov.io/gh/nar10z/go-accumulator)\n\nSolution for accumulation of events and their subsequent processing.\n\n\u003cimg alt=\"Logo\" height=\"450\" src=\"./image.png\" title=\"Logo\"/\u003e\n\n```\ngo get github.com/nar10z/go-accumulator\n```\n\n## What for?\n\nSometimes there is a situation where processing data on 1 item is too long.\nThe [go-accumulator](https://github.com/nar10z/go-accumulator) package comes to the rescue!\n\nThe solution is to accumulate the data and then process it in a batch. There are 2 situations where the processing\nfunction (**flushFunc**) is called:\n\n- Storage fills up to the maximum value (**flushSize**).\n- The interval during which the data is accumulated (**flushInterval**) passes\n\nThe accumulator provides 2 methods:\n\n- AddAsync - adding data without waiting for execution\n- AddSync - adding data with a wait for execution\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"strings\"\n\t\"sync\"\n\t\"time\"\n\n\tgoaccum \"github.com/nar10z/go-accumulator\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithTimeout(context.Background(), time.Minute)\n\tdefer cancel()\n\n\tconst (\n\t\tcountSync  = 4\n\t\tcountAsync = 3\n\t)\n\n\taccumulator := goaccum.New[string](3, time.Second, 200*time.Millisecond, func(ctx context.Context, events []string) error {\n\t\tfmt.Printf(\"Start flush %d events:\\n\", len(events))\n\t\tfor _, e := range events {\n\t\t\tfmt.Printf(\" - %s\\n\", e)\n\t\t}\n\t\tfmt.Printf(\"Finish\\n%s\\n\", strings.Repeat(\"-\", 20))\n\t\treturn nil\n\t})\n\n\tvar wg sync.WaitGroup\n\twg.Add(countSync + countAsync)\n\n\tgo func() {\n\t\tfor i := 0; i \u003c countAsync; i++ {\n\t\t\terr := accumulator.AddAsync(ctx, fmt.Sprintf(\"async #%d\", i))\n\t\t\tif err != nil {\n\t\t\t\tfmt.Printf(\"failed add event: %v\\n\", err)\n\t\t\t}\n\t\t\twg.Done()\n\t\t}\n\t}()\n\n\tgo func() {\n\t\tfor i := 0; i \u003c countSync; i++ {\n\t\t\ti := i\n\t\t\tgo func() {\n\t\t\t\terr := accumulator.AddSync(ctx, fmt.Sprintf(\"sync #%d\", i))\n\t\t\t\tif err != nil {\n\t\t\t\t\tfmt.Printf(\"failed add event: %v\\n\", err)\n\t\t\t\t}\n\t\t\t\twg.Done()\n\t\t\t}()\n\t\t}\n\t}()\n\n\twg.Wait()\n\n\taccumulator.Stop()\n}\n```\n\n### output:\n\n```text\nStart flush 3 events:\n - sync #3\n - async #0\n - async #1\nFinish\n--------------------\nStart flush 3 events:\n - async #2\n - sync #0\n - sync #1\nFinish\n--------------------\nStart flush 1 events:\n - sync #2\nFinish\n--------------------\n```\n\n## License\n\n[MIT](https://raw.githubusercontent.com/nar10z/go-accumulator/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnar10z%2Fgo-accumulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnar10z%2Fgo-accumulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnar10z%2Fgo-accumulator/lists"}