Conditional Batch Executor

A batch worker that collects tasks and executes them when conditions are met.
Caller can get the results asynchronously.
Install
go get github.com/plzzzzg/conditional-batch-executor
Examples
// init
worker := conditiaonalbatchexecutor.New(func(tasks []interface{}) map[string]interface{} {
m := map[string]interface{}{}
// do something ...
return m // key is the id from Submit
}, conditiaonalbatchexecutor.Size(3), conditiaonalbatchexecutor.Interval(time.Second*2)) // execute if size of tasks >= 3 OR after 2 seconds since last execution
// submit
resultReciever, err := worker.Submit(idStr, i)
// receive
result := <-resultReciever
Supported Conditions
Interval
worker := conditiaonalbatchexecutor.New(func(tasks []interface{}) map[string]interface{} {
m := map[string]interface{}{}
return m
}, conditiaonalbatchexecutor.Interval(time.Second*2)) // execute every 2 seconds
Size
worker := conditiaonalbatchexecutor.New(func(tasks []interface{}) map[string]interface{} {
m := map[string]interface{}{}
return m
}, conditiaonalbatchexecutor.Size(2)) // execute then buffer size reaches 2
And
worker := conditiaonalbatchexecutor.New(func(tasks []interface{}) map[string]interface{} {
m := map[string]interface{}{}
return m
}, conditiaonalbatchexecutor.And(Size(2), conditiaonalbatchexecutor.Interval(time.Second*2))) // execute then buffer size reaches 2 AND last execution happened more than 2 min ago