func WithBatching(ctx context.Context) context.Context {
	if ctx.Value(batchContextKey{}) != nil {
		panic("WithBatching was already called on a parent context")
	}
	bctx := &batchContext{
		pendingBatchGroups: make(map[funcShard]*batchGroup),
	}
	return context.WithValue(ctx, batchContextKey{}, bctx)
}
WithBatching adds batching support to the given context.
package batch
import (
	"context"
	"errors"
	"fmt"
	"sync"
	"time"
	"github.com/samsarahq/thunder/concurrencylimiter"
)
const DefaultWaitInterval = 1 * time.Millisecond
const DefaultMaxDuration = 20 * time.Millisecond
type Func struct {
	Many func(ctx context.Context, args []interface{}) ([]interface{}, error)
	Shard func(arg interface{}) (shard interface{})
	MaxSize int
	WaitInterval time.Duration
	MaxDuration time.Duration
}
type batchGroup struct {
	args []interface{}
	maxSizeCh chan struct{}
	intervalTimer *time.Timer
	doneCh chan struct{}
	result []interface{}
	err error
}
type funcShard struct {
	f     *Func
	shard interface{}
}
type batchContext struct {
	mu                 sync.Mutex
	pendingBatchGroups map[funcShard]*batchGroup
}
type batchContextKey struct{}