https://github.com/mawngo/go-batch
Simple batch processing library for golang
https://github.com/mawngo/go-batch
batch-processing golang
Last synced: 12 months ago
JSON representation
Simple batch processing library for golang
- Host: GitHub
- URL: https://github.com/mawngo/go-batch
- Owner: mawngo
- License: mit
- Created: 2024-06-07T05:14:10.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-05-19T19:13:14.000Z (about 1 year ago)
- Last Synced: 2025-05-19T20:27:12.992Z (about 1 year ago)
- Topics: batch-processing, golang
- Language: Go
- Homepage: https://godoc.org/github.com/mawngo/go-batch
- Size: 32.2 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Batch
Batch processing utilities for go projects.
## Usage
```shell
go get github.com/mawngo/go-batch
```
### Example
```go
package main
import (
"github.com/mawngo/go-batch"
"sync/atomic"
)
func main() {
sum := int32(0)
processor := batch.NewProcessor(batch.InitSlice[int], batch.AddToSlice[int]).
Configure(batch.WithMaxConcurrency(5), batch.WithMaxItem(10)).
Run(summing(&sum))
for i := 0; i < 1_000_000; i++ {
processor.Put(1)
}
processor.MustClose()
if sum != 1_000_000 {
panic("sum is not 1_000_000")
}
}
func summing(p *int32) batch.ProcessBatchFn[[]int] {
return func(ints []int, _ int64) error {
for _, num := range ints {
atomic.AddInt32(p, int32(num))
}
return nil
}
}
```
More usage can be found in [test](batch_test.go) and [examples](examples)