I don’t have an example but a concurrent solution seems straightforward to reason about. Here’s a description of where I’d start:
Perhaps have a type to send on the buffered chan from the one producer goroutine?
type Chunk struct {
Index int
Data []byte
}
Then make any number of worker goroutines that read from the buffered chan Chunk (maybe a count equal to
https://golang.org/pkg/runtime/#NumCPU) and do the processing. Then have a single consumer goroutine that reads processed Chunks from these workers via an unbuffered channel. This consumer orders the work output and returns the data once complete. Alternatively the workers could write their output into a slice or array where each index can only be written by one goroutine.
The best solution depends on your application. For a network server with multiple clients a serial approach may be simpler than a concurrent one and have similar performance. How will your batch processing be used?
Matt