{"id":20000131,"url":"https://github.com/rb-go/go-buflice","last_synced_at":"2025-11-25T22:08:51.901Z","repository":{"id":57576842,"uuid":"205913125","full_name":"rb-go/go-buflice","owner":"rb-go","description":"Golang goroutine safe buffered slice - flush slice on size limit or time limit reach","archived":false,"fork":false,"pushed_at":"2021-04-15T16:02:00.000Z","size":24,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T12:52:20.038Z","etag":null,"topics":["buffer","channels","go","gochan","golang","goroutine","slice","ticker"],"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/rb-go.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"riftbit","custom":["https://paypal.me/riftbit"]}},"created_at":"2019-09-02T18:20:47.000Z","updated_at":"2023-09-25T16:43:02.000Z","dependencies_parsed_at":"2022-09-26T19:02:39.265Z","dependency_job_id":null,"html_url":"https://github.com/rb-go/go-buflice","commit_stats":null,"previous_names":["rb-pkg/buflice","riftbit/buflice"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rb-go%2Fgo-buflice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rb-go%2Fgo-buflice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rb-go%2Fgo-buflice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rb-go%2Fgo-buflice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rb-go","download_url":"https://codeload.github.com/rb-go/go-buflice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241439470,"owners_count":19963095,"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":["buffer","channels","go","gochan","golang","goroutine","slice","ticker"],"created_at":"2024-11-13T05:13:53.293Z","updated_at":"2025-11-25T22:08:46.853Z","avatar_url":"https://github.com/rb-go.png","language":"Go","funding_links":["https://patreon.com/riftbit","https://paypal.me/riftbit"],"categories":[],"sub_categories":[],"readme":"# buflice\n\nThis package need to create buffered slice that can be flushed when reach size or duration limit  \n\n### When it can be needed?\nExample: You have a worker for rabbitmq that receives jobs from queue. You receive them one by one and process it. But sometimes \nyou need to accumulate data from jobs for batch processing in database.\n\n[Website](https://riftbit.com) | [Blog](https://ergoz.ru)\n\n[![license](https://img.shields.io/github/license/rb-pkg/buflice.svg)](LICENSE)\n[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/rb-pkg/buflice)\n[![Coverage Status](https://coveralls.io/repos/github/rb-pkg/buflice/badge.svg?branch=master)](https://coveralls.io/github/rb-pkg/buflice?branch=master)\n[![Build Status](https://travis-ci.com/rb-pkg/buflice.svg?branch=master)](https://travis-ci.com/rb-pkg/buflice)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rb-pkg/buflice)](https://goreportcard.com/report/github.com/rb-pkg/buflice)\n\n## Installation\n\n```bash\ngo get -u github.com/rb-pkg/buflice\n```\n\n## Example (dirty example)\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/rb-pkg/buflice\"\n)\n\ntype Book struct {\n\tAuthor string\n}\n\nfunc flushProcessor(chFlush chan []interface{}, chDone chan struct{}, wait *sync.WaitGroup) {\n\tfor {\n\t\tselect {\n\t\tcase data := \u003c-chFlush:\n\t\t\twait.Add(1)\n\t\t\tlog.Printf(\"%+v\", data)\n\t\t\twait.Done()\n\t\tcase \u003c-chDone:\n\t\t\tlog.Println(\"Finished flushProcessor\")\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc main() {\n\tchFlush := make(chan []interface{})\n\tchDone := make(chan struct{})\n\twait := sync.WaitGroup{}\n\n\tbfl := buflice.NewBuflice(10, 1000*time.Millisecond, chFlush)\n\n\tgo flushProcessor(chFlush, chDone, \u0026wait)\n\tbfl.Start()\n\n\tbfl.Add(Book{Author: \"Author #1\"})\n\tbfl.Add(Book{Author: \"Author #2\"})\n\tbfl.Add(Book{Author: \"Author #3\"})\n\tbfl.Add(Book{Author: \"Author #4\"})\n\tbfl.Add(Book{Author: \"Author #5\"})\n\ttime.Sleep(1111 * time.Millisecond)\n\tbfl.Add(Book{Author: \"Author #6\"})\n\tbfl.Add(Book{Author: \"Author #7\"})\n\tbfl.Add(Book{Author: \"Author #8\"})\n\tbfl.Add(Book{Author: \"Author #9\"})\n\tbfl.Add(Book{Author: \"Author #10\"})\n\t\n\terr := bfl.Close()\n\tif err != nil {\n\t\tlog.Fatalln(err)\n    }\n\n\twait.Wait()\n\tchDone \u003c- struct{}{}\n\n}\n```\n\nWill print:\n\n```bash\n2019/09/03 14:56:28 [Record #1 Record #2 Record #3 Record #4 Record #5 Record #6]\n2019/09/03 14:56:28 [Record #7 Record #8 Record #9 Record #10]\n2019/09/03 14:56:28 Finished flushProcessor\n```\n\n\n## Credits\n\nThanks to:\n\n- Everyone that [gave this repo a star](https://github.com/riftbit/buflice/stargazers) :star: - *you keep me motivated* :slightly_smiling_face: \n- [Contributors](https://github.com/riftbit/buflice/graphs/contributors) that submitted useful [pull-requests](https://github.com/riftbit/buflice/pulls?utf8=%E2%9C%93\u0026q=is%3Apr+is%3Aclosed+is%3Amerged) or opened good issues with suggestions or a detailed bug report.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frb-go%2Fgo-buflice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frb-go%2Fgo-buflice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frb-go%2Fgo-buflice/lists"}