# README
Batch
Instead of executing a task immediately whenever you receive an input, sometimes, it might be more efficient to create a batch of inputs and process all in one go.
out := make(chan int, taskCount)
processBatch := func(nums []int) error {
for _, number := range nums {
out <- number * 10
}
return nil
}
// Auto process batch every 100ms
periodicBatcher := NewBatcher(
processBatch,
WithAutoProcessInterval(100*time.Millisecond),
)
// Auto process batch when pending queue reaches 10
sizeBatcher := NewBatcher(
processBatch,
WithAutoProcessSize(10),
)
// Auto process batch every 100ms or when pending queue reaches 10
periodicSizeBatcher := NewBatcher(
processBatch,
WithAutoProcessInterval(100*time.Millisecond),
WithAutoProcessSize(10),
)
// Auto process batch when pending queue reaches 10
manualBatcher := NewBatcher(
processBatch,
)
manualBatcher.Process()
See batch_test.go
for more detailed examples on how to use this feature.
# Functions
NewBatcher returns a new Batcher.
NewMockBatcher creates a new instance of MockBatcher.
NewMockSilentBatcher creates a new instance of MockSilentBatcher.
NewSilentBatcher returns a new SilentBatcher.
WithAutoProcessByTicketBooth creates a synchronous ticket booth that can track how many ticket owners have arrived in order to start batch processing.
WithAutoProcessInterval sets the interval at which Batcher will automatically process the pending tasks.
WithAutoProcessSize sets the limit at which Batcher will automatically process the pending tasks.
WithShutdownGraceDuration specifies how long Batcher will wait for the Shutdown operation to complete before returning.
# Variables
No description provided by the author
# Structs
MockBatcher is an autogenerated mock type for the Batcher type.
MockSilentBatcher is an autogenerated mock type for the SilentBatcher type.
# Interfaces
Batcher is a batch processor which is suitable for sitting in the back to receive tasks from callers to execute in one go and then return individual result to each caller.
SilentBatcher is a batch processor which is suitable for sitting in the back to accumulate tasks and then execute all in one go silently.
# Type aliases
No description provided by the author