Problem
- How to Read File
- How to Process File (i.e Channel) Concurrently with Goroutines
Solution
Reading a File
- Spin up a
goroutineto read data from file in chunks using
scanner.Scan()
Processing Channel
- Spin Up
Ngoroutine - Each one will take a
Chunkfrom theChannel - Extract data from the
Chunkand executeprocessFn
func ProcessFile(file io.Reader, numWorkers int, chunkSize int, processFn func(data []byte))
Github Repo for code
-
Sandy10247 / go-process-file
A Sample Repo, to demonstrate File Processing concurrently
go-process-file
A Sample Repo, to demonstrate File Processing concurrently
Execution
Dev to Article



Top comments (0)