Skip to content

floatdrop/batchan

Repository files navigation

BatChan

CIGo Report CardGo ReferenceLicense: 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

go get github.com/floatdrop/batchan

Usage

package main import ( "fmt""time""github.com/floatdrop/batchan" ) funcmain(){input:=make(chanstring, 5) batches:=batchan.New(input, 3) gofunc(){inputs:= []string{"A", "B", "C", "D", "E"} for_, v:=rangeinputs{input<-v } close(input) }() forv:=rangebatches{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 file for details.

About

Channel batching

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages