My Go project breaks when I try to write concurrently.
I have a map map[string][]strings
. I want to write files concurrently, which are named as key + ".csv"
and for each value of []strings
write another row to the file with the value in it.
What I've done:
for key, val := range varValMap {
go writeCsv(key, val)
}
And the func is:
func writeCsv(variable string, values []string) {
fName := variable + ".csv"
fPath := filepath.Join(xmlFolder, "_varval", fName)
file, err := os.Create(fPath)
check(err)
defer file.Close()
for _, value := range values {
fmt.Fprintf(file, value + "
")
}
}
The program finishes with no problems detectable by me, yet with no complete result (some files are written but nothing in them), also when I remove go
from go writeCsv(key, val)
all is well in go land.