github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/utils/batch/option.go (about) 1 package batch 2 3 import ( 4 "runtime" 5 "time" 6 ) 7 8 type config struct { 9 maxWorkers int32 10 batchSize int32 11 minWaitTime time.Duration 12 } 13 14 var defaultConfig = config{ 15 maxWorkers: int32(runtime.NumCPU() * 10), 16 batchSize: 100, 17 minWaitTime: 0, 18 } 19 20 type Option func(*config) 21 22 // WithMaxWorkers sets the maximum number of workers to use. 23 // Defaults to runtime.NumCPU() * 10. 24 func WithMaxWorkers(maxWorkers int32) Option { 25 return func(c *config) { 26 c.maxWorkers = maxWorkers 27 } 28 } 29 30 // WithBatchSize sets the maximum number of entries to batch together. 31 // Defaults to 100. 32 func WithBatchSize(batchSize int32) Option { 33 return func(c *config) { 34 c.batchSize = batchSize 35 } 36 } 37 38 // WithMinWaitTime sets the minimum amount of time to wait before flushing 39 // a batch. Defaults to 0. 40 func WithMinWaitTime(minWaitTime time.Duration) Option { 41 return func(c *config) { 42 c.minWaitTime = minWaitTime 43 } 44 }