https://github.com/floatdrop/batchan
Channel batching
https://github.com/floatdrop/batchan
Last synced: 9 months ago
JSON representation
Channel batching
- Host: GitHub
- URL: https://github.com/floatdrop/batchan
- Owner: floatdrop
- License: mit
- Created: 2025-06-23T09:09:06.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-23T15:58:32.000Z (about 1 year ago)
- Last Synced: 2025-06-23T16:41:56.392Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BatChan
[](https://github.com/floatdrop/batchan/actions/workflows/ci.yaml)
[](https://goreportcard.com/report/github.com/floatdrop/batchan)
[](https://pkg.go.dev/github.com/floatdrop/batchan)
[](https://opensource.org/licenses/MIT)
A lightweight Go library for batching values from a channel with support for size-based and optional timeout-based flushing.
## Features
- Batch items from a channel based on size
- Flush batches after a timeout, even if not full
- Supports context cancellation with `WithContext` option
- Zero-dependency, idiomatic Go
## Installation
```bash
go get github.com/floatdrop/batchan
```
## Usage
```go
package main
import (
"fmt"
"time"
"github.com/floatdrop/batchan"
)
func main() {
input := make(chan string, 5)
batches := batchan.New(input, 3)
go func() {
inputs := []string{"A", "B", "C", "D", "E"}
for _, v := range inputs {
input <- v
}
close(input)
}()
for v := range batches {
fmt.Println("Got:", v)
}
// Output:
// Got: [A B C]
// Got: [D E]
}
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.