Skip to content

Pushwoosh/batcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Batcher

Batcher is a go library that allows to collect any items into a buffer and flush the buffer either when the buffer fills up or when timeout is reached.

Installation

go get github.com/pushwoosh/batcher

Example

func main() {
	b := batcher.New[int](time.Millisecond*5, 20000)

	go func() {
		for i := 0; i < 1234567; i++ {
			b.Add(i)
		}
		b.Close()
	}()

	for batch := range b.C() {
		fmt.Println("batch size:", len(batch))
	}
}