Add queue to prevent writing too many files at once.

This commit is contained in:
Mark Beamer Jr 2021-05-20 20:43:01 -04:00 committed by Niko Storni
parent 6c4db980c9
commit fa7150cf2b

View file

@ -23,6 +23,7 @@ func init() {
writeCh = make(chan writeRequest) writeCh = make(chan writeRequest)
for i := 0; i < runtime.NumCPU(); i++ { for i := 0; i < runtime.NumCPU(); i++ {
go func() { go func() {
for {
select { select {
case r := <-writeCh: case r := <-writeCh:
err := ioutil.WriteFile(r.filename, r.data, r.perm) err := ioutil.WriteFile(r.filename, r.data, r.perm)
@ -30,6 +31,7 @@ func init() {
log.Errorf("could not write file %s to disk, failed with error: %s", r.filename, err.Error()) log.Errorf("could not write file %s to disk, failed with error: %s", r.filename, err.Error())
} }
} }
}
}() }()
} }
} }