{"id":19859150,"url":"https://github.com/woorui/async-buffer","last_synced_at":"2025-06-16T22:05:01.394Z","repository":{"id":38368023,"uuid":"485024520","full_name":"woorui/async-buffer","owner":"woorui","description":"Generic Asynchronous data buffer with Automatic and Manual flushing","archived":false,"fork":false,"pushed_at":"2023-08-21T17:14:36.000Z","size":30,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-02T02:39:02.545Z","etag":null,"topics":["async","buffer","flush","go","golang","goroutine","telegraf"],"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/woorui.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":"2022-04-24T12:43:34.000Z","updated_at":"2024-05-02T06:32:16.000Z","dependencies_parsed_at":"2024-06-19T06:16:08.175Z","dependency_job_id":"c36b7da7-7b0a-4dec-b942-def4815962fa","html_url":"https://github.com/woorui/async-buffer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/woorui/async-buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Fasync-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Fasync-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Fasync-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Fasync-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/woorui","download_url":"https://codeload.github.com/woorui/async-buffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Fasync-buffer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260249958,"owners_count":22980763,"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":["async","buffer","flush","go","golang","goroutine","telegraf"],"created_at":"2024-11-12T14:25:51.149Z","updated_at":"2025-06-16T22:05:01.366Z","avatar_url":"https://github.com/woorui.png","language":"Go","readme":"# async-buffer\n\n[![Go](https://github.com/woorui/async-buffer/actions/workflows/go.yml/badge.svg)](https://github.com/woorui/async-buffer/actions/workflows/go.yml)\n[![codecov](https://codecov.io/gh/woorui/async-buffer/branch/main/graph/badge.svg?token=G7OK0KG9YT)](https://codecov.io/gh/woorui/async-buffer)\n[![Go Reference](https://pkg.go.dev/badge/github.com/woorui/async-buffer.svg)](https://pkg.go.dev/github.com/woorui/async-buffer)\n\nThe async-buffer buffer data that can be flushed when reach threshold or duration limit. It is multi-goroutinue safe.\n\n**It only support go1.18 or later**\n\n## Why you need it?\n\n### An Usecase: \n\nYou have a message queue subscriber server.\n\nThe Server receives messages one by one and inserts them into your database,\n\nBut there is a big performance gap between one by one insertion and batch insertion to your database.\n\nSo that to use async-buffer to buffer data then find timing to batch insert them.\n\n## Installation\n\n```\ngo get -u github.com/woorui/async-buffer\n```\n\n## Quick start\n\nThe `Write`, `Flush`, `Close` api are goroutinue-safed.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\tbuffer \"github.com/woorui/async-buffer\"\n)\n\n// pp implements Flusher interface\ntype pp struct{}\n\nfunc (p *pp) Flush(strs []string) error {\n\treturn print(strs)\n}\n\nfunc print(strs []string) error {\n\tfmt.Printf(\"print: %v \\n\", strs)\n\treturn nil\n}\n\nfunc main() {\n\t// can also call buffer.FlushFunc` to adapt a function to Flusher\n\tbuf := buffer.New[string](\u0026pp{}, buffer.Option[string]{\n\t\tThreshold:     5,\n\t\tFlushInterval: 3 * time.Second,\n\t\tWriteTimeout:  time.Second,\n\t\tFlushTimeout:  time.Second,\n\t\tErrHandler:    func(err error, t []string) { fmt.Printf(\"err: %v, ele: %v\", err, t) },\n\t})\n\n\t// data maybe loss if Close() is not be called\n\tdefer buf.Close()\n\n\t// 1. flush at threshold\n\tbuf.Write(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\")\n\n\t// 2. time to flush automatically\n\tbuf.Write(\"aaaaa\")\n\tbuf.Write(\"bbbbb\")\n\tbuf.Write(\"ccccc\", \"ddddd\")\n\ttime.Sleep(5 * time.Second)\n\n\t// 3. flush manually and write call `WriteWithContext`\n\tbuf.WriteWithContext(context.Background(), \"eeeee\", \"fffff\")\n\tbuf.Flush()\n}\n\n```\n\n## License\n\n[MIT License](https://github.com/woorui/async-buffer/blob/main/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoorui%2Fasync-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwoorui%2Fasync-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoorui%2Fasync-buffer/lists"}